I want to notify my web view with a button in an html file and run javascript:
function notify(str) { window.external.notify(str); }
Event shot using wv_ScriptNotify(..., ...) :
void wv_ScriptNotify(object sender, NotifyEventArgs e) { Color c=Colors.Red; if (e.CallingUri.Scheme =="ms-appx-web" || e.CallingUri.Scheme == "ms-appdata") { if (e.Value.ToLower() == "blue") c = Colors.Blue; else if (e.Value.ToLower() == "green") c = Colors.Green; } appendLog(string.Format("Response from script at '{0}': '{1}'", e.CallingUri, e.Value), c); }
I installed the html file on ms-appx-web and it works well, and I understand that the html file should be stored in a local folder. So I change ms-appx-web:///.../index.html to ms-appdata:///local/.../index.html .
Already search the microsoft forum and get this . There is a solution in this thread using resolver, but I'm still confused, how can it notify from javascript, for example, using window.external.notify ? And what event on the C # side will capture a "notification" from javascript other than "ScriptNotify"?
Update
There is a solution from here , for example using a resolver, and he said to use ms-local-stream:// instead of using ms-appdata://local so that I can still use the ScriptNotify event. But unfortunately, the example is using ms-appx , which means using InstalledLocation not LocalFolder .
Trying to search and search the msdn documentation site for ms-local-stream , but the only documentation is only the ms-local-stream format without any examples like ms-local-stream://appname_KEY/folder/file .
Based on this documentation, I made some examples to try:
public sealed class StreamUriWinRTResolver : IUriToStreamResolver {
And inside my MainPage.xaml.cs:
protected override void OnNavigatedTo(NavigationEventArgs e) {
It always gets an exception when it reaches the line StorageFile f = await StorageFile.GetFileFromApplicationUriAsync(localUri); .
If anyone has ever received this problem and already solved it, consult.