WP7 Web浏览器控件中无法通过Javascript显示警报 [英] Unable to show alert via Javascript in WP7 web browser control

查看:91
本文介绍了WP7 Web浏览器控件中无法通过Javascript显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WP7中的Web浏览器控件在网页中使用javascript显示警报框.警报没有弹出.代码有什么问题吗?或者WP7根本不支持它?

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 support it at all?

< phone:WebBrowser名称="browser" IsScriptEnabled ="True" ScriptNotify ="browser_ScriptNotify" Source ="Default.html"/>

<phone:WebBrowser Name="browser" IsScriptEnabled="True" ScriptNotify="browser_ScriptNotify" Source="Default.html"/>

内部Default.html

Inside Default.html

<html><br>
<head><br>
</head><br>
<body onload="onLoad()"><br>
    <script type="text/javascript"><br>
        function onLoad() {<br>
            alert("hello");<br>
        }<br>
    </script><br>
</body><br>
</html>

推荐答案

这是我解决的方法,我将javascript注入了要导航到的网页上,并覆盖了警告和确认框

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 + ');};

然后在脚本通知功能中使用MessageBox显示该消息.我希望它也能帮助其他人.先前的答案是一种解决方法,这就是我认为是解决问题的正确方法

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

这篇关于WP7 Web浏览器控件中无法通过Javascript显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆