Guest, register

MGTC giving away 200$ + Claim every day !!

Just 5 minutes to register a new account to claim 200$ immediately. Rewards will be distributed to your Exchange Account: Sign Up >> Simple KYC >> Community Rewards. Just register because you cost nothing. In 2017, Binance aslo gave away 100 BNB per registration, now 1 BNB > 600$. So why now you do not try it with MGTC?

Injecting JavaScript codes Into iPhone Application UIWebView In this iPhone and JavaScript tutorial, the author will guide you how to use UIWebView from iOS SDK to embed JavaScript codes into the iPhone's applications. Only a few tiny but detailed instructions in this JavaScript for iPhone tutorial, you can easily create iPhone applications on the iOS platform.

Let check out this helpful post if you want to develop/code JavaScript on iPhone. Please go to the full post page for more details.

Free iPage Web Hosting for First Year NOW

If you're still looking for a reliable web host provider with affordable rates, why you don't take a little of time to try iPage, only with $1.89/month, included $500+ Free Extra Credits for the payment of 24 months ($45)?

Over 1,000,000+ existisng customers can not be wrong, definitely you're not, too! More important, when you register the web hosting at iPage through our link, we're going to be happy for resending a full refund to you. That's awesome! You should try iPage web hosting for FREE now! And contact us for anything you need to know about iPage.
Try iPage for FREE First Year NOW

UIWebView has very few instance methods. One of them is stringByEvaluatingJavaScriptFromString, which very powerful and unfortunately poorly documented. (This is literally the extent of Apple's explanation: "Returns the result of running a script.")

Let's explore this mysterious method with a couple of examples.

A trivial example of how to use stringByEvaluatingJavaScriptFromString is to get the title of the HTML document:

NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];

You would typically place this line of code in webViewDidFinishLoad.

This technique is not limited to one-liners, or accessing simple properties. Here's an example of two lines of JavaScript code executed in order, as you would expect:

[webView stringByEvaluatingJavaScriptFromString:@"var field = document.getElementById('field_2');"
						 "field.value='Multiple statements - OK';"];

You can also call JavaScript functions this way. And if you want to call a JavaScript function that does not already exist in the web page that you're downloading, you can "inject" it yourself with this technique:

[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
						 "script.type = 'text/javascript';"
						 "script.text = \"function myFunction() { "
							"var field = document.getElementById('field_3');"
							"field.value='Calling function - OK';"

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

In essence I'm using Objective C to create a string which represents JavaScript which which when executed adds a JavaScript function to the HTML DOM. Apologies for the multiple meta levels... Let me try to untangle this line by line.

Line 1 : First we create a <script> element using JavaScript.
Line 2 : Set the type of the <script> element to text/javascript.
Line 3-6 : Set the content of the <script> element to the JavaScript function that you want to inject.
Line 7 : Add the new <script> element as a child to the <head> element of the HTML DOM.
Line 9 : Call the new JavaScript function.

Bonus tip: You can break up NSString constants over multiple lines in Xcode for increased readability. Just end the line with a double-quote character and begin the next line with a double-quote character. At compile time these lines will be joined into one string. So the string that begins with "var script" on Line 1 is one continuous string ending with "appendChild(script);" on Line 7.

Although it's not critical for the discussion above, here's the HTML that the example JavaScript refers to:


    <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0"/>
    <p>This is the UIWebView</p>

      <input id="field_1" type="text" name="value" /><br/>
      <input id="field_2" type="text" name="value" /><br/>
      <input id="field_3" type="text" name="value" /><br/>


You can use this generic technique to add JavaScript to any web page that you're downloading and displaying in a UIWebView. The technique and the possibilities are similar to what you can do with the Greasemonkey plugin for Firefox.

JavaScript by day

Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web