问题
I am writing a windows 8 application in c# xaml , I am using using a web view, I want to limit the URLs to be loaded in the web view as there are some buttons which are not necessary and we have specific web apps for that purpose. So can we limit the URLs that can be loaded in a web view?
A way I thought of was to check for an event which will be fired once we start navigating to a new URL. But I could not get one in MSDN doc. Any thoughts?
回答1:
While not as simple as having a Navigating event, there is a workaround you can do leveraging ScriptNotify.
How to emulate navigating event in the WebView
It basically amounts to iterating over every a tag in the document, and adding a custom Javascript call letting you know that something is happening. This isn't fool proof however, as it's possible the navigation is triggered via Javascript and not someone clicking on a link.
There are a few other issues you can encounter when using the WebView. Here is another article covering them and some workarounds.
Metro WebView Source Workarounds
来源:https://stackoverflow.com/questions/14325007/is-there-a-way-limit-the-no-of-urls-in-web-view