views:

52

answers:

5

Hi all,

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/javascript';"  
  "script.text = alert(); "
  "document.getElementsByTagName('body').appendChild(script);"]; 

But I cant see alert in this.

Can any one please help me in this?

A: 
[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....

rohit
Its not working :(
A: 

Its not working :(

A: 

document.getElementsByTagName('body') ...

do you have this body tag in that view?????

rohit
A: 
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...

rohit
A: 

Got the...........solution?

rohit
nope.......................