[UWP]如何通过webview UWP中的AngularJS检测网址更改 [英] [UWP]How to detect url change through AngularJS in webview UWP

查看:85
本文介绍了[UWP]如何通过webview UWP中的AngularJS检测网址更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

 


我在项目Visual Studio UWP中使用WebView,它加载了一个使用AngularJS的网站URL。

I am using WebView in a project Visual studio UWP, which load a url of website which using AngularJS.

当它加载一个新的URL(AngularJS路由)时,它没有通过WebView方法检测到(webview方法
NavigationStarting

When its load an new url (AngularJS routing) its not detecting by WebView method (webview method NavigationStarting)

如何检测浏览器中的网址是否发生变化?

How can i detect if url change in browser?

我在 ApplicationContentUriRules 中添加了我的网站(https:/ /my.site.com)但未在下一页导航网站中触发事件ScriptNotify。在webview中仅启动加载网站

i'm added my site in a ApplicationContentUriRules (https://my.site.com) but not fired event ScriptNotify in a next page navigating of site. Fire only load site in a webview

这是我的webview声明

this is my webview declaration




推荐答案

Hello Luigi Rux,

Hello Luigi Rux,

NavigationStarting事件发生在WebView导航到新页面之前。但是你说你使用过AngularJS Routing,它用来让你的应用程序成为SPA(单页面应用程序),而不用重新加载页面。它只是使用一个容器来放置路由提供的内容
。所以,这个事件不会被解雇。

NavigationStarting event occurs before the WebView navigates to new page. But you said you used AngularJS Routing, it’s used to let your application to be a SPA (Single Page Application), with no page reloading. It just uses a container to put the content provided by the routing. So, this event will not be fired.

在你的情况下,你可以考虑使用
FrameNavigationStarting
事件。

In your case, you could think about using FrameNavigationStarting event.

>>"我" m在ApplicationContentUriRules(https://my.site.com)中添加了我的网站,但未在下一页导航网站中触发事件ScriptNotify。"

我不确定您是否在应用清单中添加了正确的Uri规则。请确保这是正确的。另外,你在JS代码中调用了"window.external.notify"吗?如果没有,ScriptNotify事件将不会被触发。

I’m not sure if you have added the correct Uri rules in app manifest. Please make sure that’s correct. Besides, have you called "window.external.notify" in your JS code? If not, the ScriptNotify event will not be fired.

在这里,我做了一个简单的代码示例来测试ScriptNotify事件,它运行良好。请检查它以供参考。

Here, I’ve made a simple code sample to test ScriptNotify event, it worked well. Please check it for reference.

<WebView Source="https://www.w3schools.com/code/tryit.asp?filename=FE5T5KX3I8MR" FrameNavigationStarting="WebView_FrameNavigationStarting" ScriptNotify="WebView_ScriptNotify"></WebView>

private void WebView_FrameNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
        {
            System.Diagnostics.Debug.WriteLine("FrameNavigationStarting fired...url: " + args.Uri);
        }

        private void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e.CallingUri+" value: "+e.Value);
        }





我添加了  AngularJS点击事件对于每个链接。

I added AngularJS click event for every link.

<body ng-app="myApp" ng-controller="myCtrl">

<p><a href="#/" ng-click="myFunction('main')">Main</a></p>

<a href="#red" ng-click="myFunction('red')">Red</a>
<a href="#green" ng-click="myFunction('green')">Green</a>
<a href="#blue" ng-click="myFunction('blue')">Blue</a>

<div ng-view></div>

<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function(


routeProvider){
routeProvider) {


routeProvider
.when(" /",{
templateUrl:" main.htm"
})
.when(" / red",{
templateUrl:" red.htm"
})
.when(" / green",{
templateUrl:" green.htm"
})
.when(" / blue",{
templateUrl:" blue.htm"
});
});
app.controller('myCtrl',function(
routeProvider .when("/", { templateUrl : "main.htm" }) .when("/red", { templateUrl : "red.htm" }) .when("/green", { templateUrl : "green.htm" }) .when("/blue", { templateUrl : "blue.htm" }); }); app.controller('myCtrl', function (


这篇关于[UWP]如何通过webview UWP中的AngularJS检测网址更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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