简体   繁体   中英

How to prevent AJAX navigation away from page in WebBrowser control in WP7

I have a page loaded onto my webBrowser control, and I want to prevent navigation away to a certain URL, based on some condition. However all these navigations away are asynchronous, through AJAX. I have tried using the e.Cancel = true; to prevent navigation away, but it still navigates away. What can I do to prevent this navigation?

    private void webBrowser_Navigating(object sender, Microsoft.Phone.Controls.NavigatingEventArgs e)
    {
        MessageBox.Show("Navigating"); //This gets executed during AJAX navigation, which means the Navigating event occurs even during AJAX navigations
        if (e.Uri.ToString().Contains("#!/restricted"))
        {
            MessageBox.Show("URL Found. Trying to cancel"); //This also gets executed when navigating away to that specific link. AJAX link, like ../index.php#!/restricted.php
            e.Cancel = true;
            return;
        }
     }

Printing the webBrowser.Source.ToString() in a MessageBox after execution still shows the first URL as the webBrowser's source, as though it hasn't navigated at all, though it still navigates away. Disabling JavaScript isn't an option, as some other elements of the main page still require JavaScript.

Thanks.

您可以尝试编辑页面的JS代码,并从其中删除所有ajax导航。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM