1

I want to print variable value of javascript function in xcode console. This is the script

<script language="javascript" type="text/javascript">
function myFunction() {
var abc =@"My Value";
      alert('Hello world');
}
</script>

With help of

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

I able to run function and alert of @"Hello world" is display.

My main concern is NSLog(@"abc Value %@",?); How to access abc value ="My Value";

I am new in javascript and don't have much knowledge of basic of javascript.

waiting for replay'

Thanks

5
  • Have you tried this -- alert(abc); Commented Aug 8, 2013 at 6:19
  • plese explain in detail ,where to call alert(abc); Commented Aug 8, 2013 at 12:25
  • instead of alert('Hello world'); change it to alert(abc); Commented Aug 8, 2013 at 13:09
  • And if you require this abc value to your objective c code then return abc from javascript function. And in objective c, assign to some string variable. Commented Aug 8, 2013 at 13:10
  • thanks.it work.insted of alert(abc),I return value in js function and access it as NSLog(@"string %@",[webView stringByEvaluatingJavaScriptFromString:@"myFunction()"]);Thanks again Commented Aug 9, 2013 at 6:45

1 Answer 1

1

See this url

iphone app and uiwebview with javascript code can i access variables?

Sign up to request clarification or add additional context in comments.

3 Comments

Hi,I run above code in shouldStartLoadWithRequest but string is blank.does i have to change in javascript?
Hi i have run in webViewDidFinishLoad delegate but still string is blank. i run in all possible ways.what is wrong?
see this url for more info .... stackoverflow.com/questions/13747558/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.