gpt4 book ai didi

javascript - 在 webview WinRt 中获取导航 url

转载 作者:行者123 更新时间:2023-11-30 05:52:37 26 4
gpt4 key购买 nike

我正在注入(inject)此 JS 以在运行时获取 navigating url(destination)。我收到 JS 异常。怎么了?

     static String NAVIGATING_FUNCTION = "window.onbeforeunload = function(){ window.external.notify(' + location.href + ''); };";
webView.InvokeScript("eval", new String[] { NAVIGATING_FUNCTION });

请问如何使用这个JS取消导航返回上一页?

最佳答案

如果我没理解错的话,因为我还没有使用过WebView,你想在离开前报告当前位置然后取消吗?

你可以试试这个:

window.onbeforeunload = function(){ window.external.notify(location.href); return false; };

我不确定您为什么要在其中引用; location.href 将在该 Web View 中,并将作为字符串传递。

此外,请查看对 this thread 的回复.其中一位说:

Did you get your problem solved? In the Release Preview, you need to add some code that looks like this:

        List<Uri> allowedUris = new List<Uri>();
allowedUris.Add(e.Uri);
allowedUris.Add(new Uri("http://www.bing.com"));
Browser.AllowedScriptNotifyUris = allowedUris;

另一件事,这个线程:Can I get the current HTML or Uri for the Metro WebView control? ,讨论 LoadCompleted 事件处理程序。

看看是否有帮助。

关于javascript - 在 webview WinRt 中获取导航 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13800898/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com