I receive some html data from server, and I try to build a webview to show these data. Then I need to set some labels to navigate to other page of UWP.
In Windows Phone 8 projects, I can add a label like this to navigate to another page and pass parameters.
But UWP doesn't support it anymore, so how to navigate to another page and pass parameters??
Here is a solution.
1.This is the string that webview will navigate to.
"<html>"+
"<body>"+
"<script type='text/javascript'>" +
"function Click()" +
"{window.external.notify('parameter1+" + "parameter2"+"...");}" +
"</script>" +
"<a href='#' onclick='Click();'>" + "NameOfLabel</a>" +
"</body>"+
"</html>";
2.Webview add a scriptnotify event in your xaml.
<WebView ScriptNotify="webView_ScriptNotify"></WebView>
3.Get parameter from javascript
private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
{
//Get the paramter from javascript
string parameter=e.value;
}
4.One more, there is another wat to pass complicate parameters like a class. But I can't find this artilce, I will add the url later if I find it.