javascript - Can't load JS into WebView in Swift -


i'm trying inject javascript web page i'm loading webview. got far this:

override func webview(sender: webview!, didclearwindowobject windowobject: webscriptobject!, forframe frame: webframe!) {     if (webview.mainframedocument != nil) { // && frame.domdocument == webview.mainframedocument) {         let document:domdocument = webview.mainframedocument         let hangoutsmode: string? = preferences.getstring("hangoutsmode")         let windowscriptobject = webview.windowscriptobject;         windowscriptobject.setvalue(self, forkey: "ginbox")         windowscriptobject.evaluatewebscript("console = { log: function(msg) { ginbox.consolelog(msg); } }")          let path = nsbundle.mainbundle().pathforresource("ginboxtweaks", oftype: "js", indirectory: "assets")         let jsstring = string(contentsoffile: path!, encoding: nsutf8stringencoding, error: nil)         let script = document.createelement("script")         let jstext = document.createtextnode(jsstring)         let bodyel = document.getelementsbyname("body").item(0)          script.setattribute("type", value: "text/javascript")         script.appendchild(jstext)         bodyel?.appendchild(script)          windowscriptobject.evaluatewebscript(string(format: "console.log('test'); hangoutsmode(%@)", hangoutsmode!))     } } 

which worked in objective c, no longer in swift. i'm not sure goes wrong exactly, can't find bodyel , remains nil. tried modifying (or removing) if on outside of it, nothing.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -