Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WebView Doesn't Understand JavaScript Call of alert() (Windows 8 XAML Application)

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.

like image 475
user1325179 Avatar asked Dec 27 '22 19:12

user1325179


1 Answers

Alert 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#.

like image 55
JP Alioto Avatar answered Dec 29 '22 09:12

JP Alioto