Running JavaScript in a UIWebView before any other JavaScript is run


Running JavaScript in a UIWebView before any other JavaScript is run



I have a UIWebView component that is going to load a webpage which might contain JavaScript. I want to run some JavaScript of my own before any JavaScript on the loaded webpage runs. I know I can use [myWebView stringByEvaulatingJavaScriptFromString:] on the webViewDidFinishLoad: delegate of the UIWebView, however this will only run my JavaScript after the JavaScript on the webpage is run.

Is the only solution to inject my JavaScript into the source code of the webpage? For example, I would put it immediately after the <head> tag to insure it is the first JavaScript that is run.




Responding to touchesBegan in UIPickerView instead of UIView

1:



Two alert views in same view controller
I would like an answer to this question as well.


CALayer addSublayer increasing retain count?
I can get it to work for the initial loading of the page by putting [myWebView stringByEvaluatingJavaScriptFromString: js] inside webViewDidStartLoad.


My iphone application crashes
On refresh, however, it does not appear to work..
What is the best way to download image data from ASP.NET to iphone?
Edit: I found this work-around (similar to the suggestion in your question.) Not sure how robust it is.


Performance problems on iPhone using simple graphics
http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/.
Converting OpenGL Primitives to OpenGLES


EXC_BAD_ACCESS error

2:


Check this post about JS execution order.

There is another tutorial here for the same issue.

If you have a problem with a specific piece of code add it here in a detailed example and will see what it can be done..



86 out of 100 based on 46 user ratings 1046 reviews