簡體   English   中英

如何防止WP7中的WebBrowser控件中的AJAX導航離開頁面

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

我有一個頁面加載到我的webBrowser控件上,並且我想根據某些情況阻止導航到某個URL。 但是,所有這些導航都是通過AJAX異步進行的。 我已經嘗試使用e.Cancel = true; 以防止導航,但它仍然可以導航。 我該怎么做才能防止這種導航?

    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;
        }
     }

執行后在MessageBox中打印webBrowser.Source.ToString()仍然顯示第一個URL作為webBrowser的源,好像它根本沒有導航,盡管它仍然可以導航。 不能選擇禁用JavaScript,因為主頁的其他某些元素仍然需要JavaScript。

謝謝。

您可以嘗試編輯頁面的JS代碼,並從其中刪除所有ajax導航。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM