iphone - How to inject html into a webview? -


Problem: I have a webview which is loading a page from Http: // somerandomsite-here Before the page is loaded I & lt; Head & gt; I want to block reference to a .js in which is in my bundle.

How can I do this?

I received the answer:

  NSString * path = [[ NSBundle main bundle] pathForResource: @ "test" type: @ "js"]; NSString * jsCode = [NSString stringWithContentsOfFile: Path Encoding: NSUTF8StringEncoding Error: Zero]; [SourceWeb StringByViewingJavascriptFormString: JSCoda];  

Put this code in the test.js in the function that you will call (see below)

  function setup () {var fileref = document CreateElement ('Script') fileref.setAttribute ("type", "text / javascript") fileref.setAttribute ("src", "filename.js");}  

when you think If this is a typical case for you, call it:

  NSString * setup = [NSString stringWithFormat: @ "setup ()"]; [SourceWeb StringBible Evalating JavascriptFramesString Setup];  

Comments