[android]Adding properties to window object of an iFrame using WebView APIs

SerrKrott

New Member
I am developing a Web based Android application using WebView where the web content can have iFrames. The WebContent's main page (e.g.: index.html) is loaded using WebView's Load URL method as below\[code\]mWebView.loadURL("index.html");\[/code\]I need to inject in an iframe window object, certain properties which are loaded through the java script files in my android application (E.g: sample.js Java script files may be present in the Assets folder)Could anybody let me know how to add java script properties to the window object of an iFrame through WebView APIs in Android ?I tried using the WebView's LoadURL method to add properties into window object of an iFrame but everytime it add these properties into main page's window object.Below is the code to load my Java script files which has the references / properties.\[code\]try{InputStream inputStream = null;byte[] buffer = null;inputStream = mAssetManager.open("sample.js");buffer = new byte[inputStream.available()]; inputStream.read(buffer); inputStream.close(); String text = new String(buffer); super.loadUrl("javascript:"+ text);}catch (Exception e){}\[/code\]iFrame is loaded from the main page (index.html) as below\[code\]<html><title>Test Page</title> <script> </script><body><iframe src="http://stackoverflow.com/questions/9886799/iframe.html" onload="MyFunction()"></iframe> \[/code\]iFrame HTML content is below, here we get unreferenced exception for "myjavascriptobject" defined in Java script file (sample.js) of my Android Application\[code\]<title>iFrame</title> <body id="body" onload = "Test()"> <script>function Test(){alert(myjavascriptobject);}</script>\[/code\]Here is the code where "myjavascriptobject" reference is defined in sample.js\[code\]myjavascriptobject = {};\[/code\]
 
Top