iphone - UIWebView stringByEvaluatingJavaScriptFromString Issue -


i working on uiwebview. want add div content loaded webview. that, have written code follows :

    nsstring *strinputjs = [nsstring stringwithformat:@"var newdiv = document.createelement('div');newdiv.innerhtml = '<h1>hi there!</h1>';document.body.appendchild(newdiv);newdiv.style.height =  100 + 'px';"];      nsstring *strresult = [_webview stringbyevaluatingjavascriptfromstring:strinputjs]; 

but not working. tried same javascript html page follows :

    <html>     <head>     <title>jstrial</title>     </head>     <body>     <script>     var newdiv = document.createelement('div');     newdiv.innerhtml = '<h1>hi there!</h1>';     document.body.appendchild(newdiv);     newdiv.style.height =  100 + 'px';     </script>     </body>     </html> 

i opened html page in safari browser, safari browser in iphone simulator. worked well.

the web view has been loaded @ point trying inject new js. found was, newdiv.style null.

what wrong code?

note never used variable numberofpixelsforpadding.

  • check did u set delegate correctly
  • call stringbyevaluatingjavascriptfromstring in webviewdidfinishload

    -(void) webviewdidfinishload:(uiwebview *)webview { nsstring *strinputjs = [nsstring stringwithformat:@"var newdiv = document.createelement('div');newdiv.innerhtml = '

    hi there!

    ';document.body.appendchild(newdiv);newdiv.style.height = 100 + 'px';"];

    [webview stringbyevaluatingjavascriptfromstring:strinputjs];

    }

note :

nsstring *strinputjs = [nsstring stringwithformat:@"var newdiv = document.createelement('div');newdiv.innerhtml = '<h1>hi there!</h1>';document.body.appendchild(newdiv);newdiv.style.height =  100 +  '%ipx';",numberofpixelsforpadding]; 

i think help..!!


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -