Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You wan to <em>call</em> the function, not just refer to it:</p> <pre><code>myLabel.text = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent()"]; </code></pre> <p>the key bit is at the end:</p> <pre><code>...documentElement.textContent()"]; // ^^ </code></pre> <p>Since JavaScript functions are first-class objects, when you do:</p> <pre><code>x = functionName; </code></pre> <p>...<code>x</code> receives a reference to the function. In your case, since the UIWebView then coerces it to a string, you end up calling <code>toString</code> on the function, which on most JavaScript implementations gives you the code of the function (although this is not specified by any standard).</p> <p>To actually <em>call</em> a function, you put parentheses after it (with nothing in them, if there are no arguments you need to pass; or with arguments in them if you do), e.g.:</p> <pre><code>x = functionName(); </code></pre> <p>Disclosure: I know nothing about iOS development, Objective-C, or <code>UIWebView</code>, but I was able to quickly find the <a href="https://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html" rel="nofollow"><code>stringByEvaluatingJavaScriptFromString</code></a> function you were using, and then confirmed via <a href="http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview" rel="nofollow">this page</a> that the string after the <code>@</code> needs to be valid JavaScript code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload