user825835
user825835

Reputation:

How to inject javascript in my UIWebview

i have a web view, in my webview i want to inject the following javascript code.Please help me thanks..

enter image description here

Upvotes: 1

Views: 4456

Answers (1)

Alex Terente
Alex Terente

Reputation: 12036

[webView stringByEvaluatingJavaScriptFromString:@"your script"];

stringByEvaluatingJavaScriptFromString:

Returns the result of running a script. - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script Parameters

script

The script to run.

Return Value

The result of running script or nil if it fails.

Discussion

JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script. This is likely to occur at a random place in your code, so unintended consequences may result. This limit is imposed because JavaScript execution may cause the main thread to block, so when scripts are running, the user is not able to interact with the webpage.

JavaScript allocations are also limited to 10 MB. The web view raises an exception if you exceed this limit on the total memory allocation for JavaScript. Availability

Available in iOS 2.0 and later.

Upvotes: 4

Related Questions