Unable To Show Alert Via Javascript In Wp7 Web Browser Control
I am trying to show alert box using javascript in a webpage using web browser control in WP7. The alert is not popping up. Is there anything wrong in the code or WP7 doesn't suppor
Solution 1:
Are you able to get the default.html resource loaded? Have a look at http://blogs.msdn.com/b/dohollan/archive/2010/08/25/adventures-with-the-windows-phone-7-webbrowser-control.aspx first.
UPDATED TO INCLUDE SAMPLE CODE FOR HOW TO ACHIEVE AN INTENDED EFFECT:
The HTML:
<htmlxmlns="http://www.w3.org/1999/xhtml" ><head><title></title><scripttype="text/javascript" >functionShowNameAlert(name) {
window.external.notify("Hello " + name);
}
</script></head><bodyonload="ShowNameAlert('Jojo');">
Bla bla
</body></html>
The C# code-behind:
privatevoidSomeBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
MessageBox.Show(e.Value);
}
The XAML:
<phone:WebBrowserx:Name="SomeBrowser"ScriptNotify="SomeBrowser_ScriptNotify"IsScriptEnabled="True"Source="test.html"/>
Solution 2:
This is how I solved it, I injected the javascript onto the webPage to which I navigate, and overrided the alert and confirm boxes
window.alert = function(__msg){window.external.notify(' + __msg + ');};
Then in the script notify function displayed that message using MessageBox. I hope it helps others too. The previous answer was a workaround, this is what I feel is the correct solution to my problem
Post a Comment for "Unable To Show Alert Via Javascript In Wp7 Web Browser Control"