在Angularjs做一个Android应用程序关闭一个子窗口 [英] Close a child window in an Android app made with Angularjs

查看:95
本文介绍了在Angularjs做一个Android应用程序关闭一个子窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码与Angularjs和科尔多瓦的Andr​​oid应用程序,但我有一个问题:
对于一个OAuth叫我需要打开一个新的窗口,转到withings网站,当我来到我的回调URL关闭窗口。

I'm coding an Android app with Angularjs and cordova, but I have a problem: For an oauth call I need to open a new window, go to the withings site and when I come on my callback url close the window.

我曾尝试使用的setInterval(或$间隔)检查每2秒,如果我用我的API的调用收讫的相关信息。它正常工作的计算机上的镀铬,但是当我编译应用程序与科尔多瓦我从来没有在循环进入。

I have tried to use setInterval (or $interval) to check every 2 seconds if I reveived the infos by a call to my API. It works fine on a computer in chrome but when I compile the app with Cordova I never enter in the loop.

于是,我试图抓住一个事件或$看我的新窗口的URL,但我只在第一个URL变化执行一次,我的功能,即使我给API调用产生错误。

So I tried to catch an event or $watch on the url of my new window but I execute only once my function at the first url change even if my call to the API result an error.

这是我最后的code,但我尝试了很多不同的测试:

This is my last code but I tried a lot of different tests :

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

如果您有任何想法,使这项工作,会很开心。

If you have any idea to make this work, would be very happy.

感谢由前进!

推荐答案

最后,我找到了解决方法:

Finally I found a solution:

我在安装插件科尔多瓦和inAppBrowser使用此code

I install the cordova plugin inAppBrowser and use this code

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

要小心,如果你不加'的位置=无'开放将无法正常工作。

Be careful if you don't add 'location=no' in open it won't work.

这篇关于在Angularjs做一个Android应用程序关闭一个子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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