admin管理员组文章数量:1279057
I'm writing a Windows 8 application in C# and XAML that hosts a Web page in a WebView. The Web page makes calls to alert() and confirm(), but the WebView throws exceptions, saying, "'alert' is undefined," or "'confirm' is undefined." Can alert() and confirm() be enabled, or do I need to write code to emulate their normal function? And if I need to write them myself, how should I begin such an undertaking? Thank you.
I'm writing a Windows 8 application in C# and XAML that hosts a Web page in a WebView. The Web page makes calls to alert() and confirm(), but the WebView throws exceptions, saying, "'alert' is undefined," or "'confirm' is undefined." Can alert() and confirm() be enabled, or do I need to write code to emulate their normal function? And if I need to write them myself, how should I begin such an undertaking? Thank you.
Share Improve this question asked Aug 8, 2012 at 15:50 user1325179user1325179 2,1153 gold badges23 silver badges31 bronze badges3 Answers
Reset to default 5Alert and confirm will not work from a WebView. You can use WebView.ScriptNotify to receive an event from your script on your page and use that event to show a dialog box using the MessageDialog class.
In your script where you want the alert ...
window.external.notify('foo');
And use the example in the WebView.ScriptNotify method in your C#.
You need to do some workaround. I did this and it worked for me.
window.alert = function(__msg){window.external.notify(' + __msg + ');};
refer a similar question of mine for windows phone here
You will need to write code to enable them. Note that this is true in a HTML5 Win8 app as well as XAML.
For script that can access WinRT, you can use Windows.UI.Popup.MessageDialog:
(new Windows.UI.Popup.MessageDialog("Hello!", "Wele")).showAsync().done(dismissedHandler)
Note that these are async, and not block execution.
For acquiring information form the user -- e.g text input from the user, there is nothing standard, and you'll need to create a new set of mark up for that.
本文标签: C WebView Doesn39t Understand JavaScript Call of alert() (Windows 8 XAML Application)Stack Overflow
版权声明:本文标题:C# WebView Doesn't Understand JavaScript Call of alert() (Windows 8 XAML Application) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741218273a2360474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论