开发者

Script in iPhone SDK

开发者 https://www.devze.com 2023-01-09 08:33 出处:网络
Can any one help me, how to write a script in iPhone SDK,without HTML string. I am trying this: [webView stringByEvaluatingJavaScriptFromString:@

Can any one help me, how to write a script in iPhone SDK,without HTML string.

I am trying this:

[webView stringByEvaluatingJavaScriptFromString:@
  "var script = document.createElement('script');"  
  "script.type = 'text/javascrip开发者_运维技巧t';"  
  "script.text = alert(); "
  "document.getElementsByTagName('body').appendChild(script);"]; 

But I cant see alert in this.

Can any one please help me in this?


[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"  
                         "script.type = 'text/javascript';"  
                         "script.text = \"function myFunction() { "  
                            "alert();"  
                          "}\";"  
                         "document.getElementsByTagName('body').appendChild(script);"];  

[webView stringByEvaluatingJavaScriptFromString:@"myFunction();"]; 

Try this....


document.getElementsByTagName('head')[0].appendChild(script);

Try this also...because document.getElementsByTagName('head') returns collection and hence get the first tag from that collection.

But it seems we need to have the HTML,head and body tags in the web page..Try the above code...if that wont work try keeping the html code like <html<head></head><body></body></html> and you can get the work around...

0

精彩评论

暂无评论...
验证码 换一张
取 消