I am struggling with execution of Javascript methods on a Webbrowser control in WP8 application . XAML i used is
<phone:WebBrowser IsScriptEnabled="True" x:Name="mainBrowserControl" Grid.Row="2"/>
And on button click event i ad the external javascript file testjs.js (This file is a part of aplication package and is inside the xap file) to the head section of currently loaded html page like
string root = Package.Current.InstalledLocation.Path;
string jsfile_path = string.Format("{0}/testjs.js", root);
var script = string.Format(@"var script=document.createElement('script');
script.src=""{0}"";
document.getElementsByTagName('head')[0].appendChild(script);", jsfile_path);
mainBrowserControl.InvokeScript("eval", script);
Then on another button click even i tried to execute one javascript method inside the testjs.js file like
mainBrowserControl.InvokeScript("eval", "callMe();");
But it returns the error
An exception of type 'System.SystemException' occurred in Microsoft.Phone.Interop.ni.dll but was not handled in user code
Additional information: An unknown error has occurred. Error: 80020101.
The contents inside testjs.js file is just 3 simple functions. My ultimate aim is to interact (send and receive value to and from javascript functions)with an external javascript file like testjs.js from my application
function callMe() {
alert("hello called");
}
function showSum(val1, val2) {
alert(val1 + val2);
}
function addTwo(val1,val2) {
return val1+val2;
}
How can i call these methods on testjs.js from my windows phone app