如何获得Webview的“navigatedTo”属性? [英] How to get Webview's "navigatedTo" property?

查看:435
本文介绍了如何获得Webview的“navigatedTo”属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Internet Explorer中打开点击的网址,而不是在网页浏览中打开,所以我想抓住在当前网页后加载webview的uri。我不想注入一个已加载的事件,因为我想在它打开任何内容之前捕获它并且i
想要取消webview中的加载。

I want to open clicked urls in Internet Explorer and not inside the webview, so i want to catch the uri that webview is going to load after the current page. I don't want to inject a loaded event because i want to catch it before it opens anything and i want to cancel the loading inside the webview.

这可能吗?

推荐答案

是的,你可以,但只能通过java脚本。

你必须通过所有链接和将所有目标设置为_blank。

Yes you can but only through java script.
You have to go through all links and set all targets to _blank.

以下是我的同事设法做到的事情:

Here is how my co-worker managed to do it:

public InternalWebView()
        {
            InitializeComponent();

            UxWebView.LoadCompleted += UxWebView_LoadCompleted;
        }

        void UxWebView_LoadCompleted(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
        {
            UxWebView.InvokeScript(
                "eval",
                new[]
                    {
                        "function myFunction(){try{var elements = document.getElementsByTagName(\"a\");var numberOfelements = elements.length;for (var i = 0; i < numberOfelements; i++) {var tlink = elements[i]; tlink.removeAttribute(\"target\");
tlink.target = \"_blank\";}} catch (e) {}}; myFunction();"
                    });
        }


这篇关于如何获得Webview的“navigatedTo”属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆