I am injecting this JS to get the navigating url (destination) at run time. I am getting JS exceptions. What is wrong?
static String NAVIGATING_FUNCTION = "window.onbeforeunload = function(){ window.external.notify(' + location.href + ''); };";
webView.InvokeScript("eval", new String[] { NAVIGATING_FUNCTION });
Also please tell me how to cancel the navigation and return back to the previous page using this JS?
If I understand correctly, since I haven’t used the WebView (yet), you want to report the current location before leaving and then cancel it?
You could try this:
I am not sure why you had quotes in there;
location.hrefwould be in that web view, and it would be passed as a string.Also, take a look at the responses to this thread. One of them says:
Another thing, this thread: Can I get the current HTML or Uri for the Metro WebView control?, talks about the LoadCompleted event handler.
See if that helps.