gpt4 book ai didi

javascript - 关闭使用 Angularjs 制作的 Android 应用程序中的子窗口

转载 作者:行者123 更新时间:2023-11-28 07:34:33 25 4
gpt4 key购买 nike

我正在使用 Angularjs 和 cordova 编写一个 Android 应用程序,但我遇到了一个问题:对于 oauth 调用,我需要打开一个新窗口,转到 withings 网站,当我看到回调 URL 时,关闭窗口。

我尝试使用 setInterval (或 $interval)每 2 秒检查一次是否通过调用 API 接收到信息。它在 Chrome 计算机上运行良好,但当我使用 Cordova 编译应用程序时,我从未进入循环。

因此,我尝试在新窗口的 url 上捕获事件或 $watch,但即使我对 API 的调用导致错误,我也仅在第一个 url 处的函数发生更改时执行。

这是我的最后一个代码,但我尝试了很多不同的测试:

var newWindow = $window.open(result.res);
var unwatch = $scope.$watch(window.location, function() {
$http.get(url)
.success(function(result) {
newWindow.close();
unwatch();
$location.path('/tab/dash');
})
.error(function(error) {
console.log(error);
});
});

如果您有任何想法让这项工作成功,我会非常高兴。

提前致谢!

最佳答案

最后我找到了解决方案:

我在AppBrowser中安装cordova插件并使用此代码

var windowWithings = $window.open(result.res, '_blank', 'location=no');
windowWithings.addEventListener('loadstart', function(event) {
$http.get(url)
.success(function(result) {
windowWithings.close();
$location.path('/tab/dash');
})
.error(function(error) {
console.log(error);
});
});

要小心,如果你不在 open 中添加 'location=no' ,它将无法工作。

关于javascript - 关闭使用 Angularjs 制作的 Android 应用程序中的子窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28752424/

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