不可能关闭inAppBrowser窗口[Solved] [英] impossible to close inAppBrowser window [Solved]

查看:242
本文介绍了不可能关闭inAppBrowser窗口[Solved]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以打开我的窗口,并在里面做很多事情,例如通过Linkedin或Facebook登录。但我不能关闭它返回到我的应用程序。

I can open my window, and do a lot of things inside of it, for example login via Linkedin or Facebook. But I cannot close it to return to my app.

1 /我试图捕获事件来跟踪url并在url包含特定关键字时关闭窗口。但事件从未被解雇。我从来没有任何警报。

1/ I tried to catch events to track the url and close the window when the url contains a particular keyword. But the event is never fired. I never have any alert.

    var ref = window.open(url, '_blank', 'location=no');

    ref.addEventListener('loadstart', function(event)
    {
        alert(event.url);
    });

    ref.addEventListener('loadstop', function(event) 
    {
        alert(event.url);
    });

2 /所以我试图找到一种方法来检查ref.location.url从第一个窗口每n秒。但ref.location.url不存在。我没有看到从父窗口访问inapp当前网址的方法。

2/ So I tried to find a way to check ref.location.url from the first window every n seconds. But ref.location.url doesn't exist. I don't see a way to access the inapp current url from the parent window.

3 /我有一个想法给一个名称的inapp窗口。但inappbrowser插件不允许给一个名称给窗口打开。所以父窗口也不能检查子窗口的url。

3/ I had the idea to give a name to the inapp window. But the inappbrowser plugin doesn't allow to give a name to the window to open. So the parent window cannot check the url of the child window that way as well.

4 /我试图要求子进程inapp窗口关闭:cordova不想一个javascript来关闭当前窗口。

4/ I tried to ask the child inapp window to close : cordova doesn't want a javascript to close the current window.

 self.close();  => cannot
 window.close(); => cannot

5 /我试图还原到cordova.js 2.9.0-0-g83dc4bd,it didn

5/ I tried to revert to cordova.js 2.9.0-0-g83dc4bd , it didn't work as well.

所以,我可以在我的应用程序中打开一个弹出窗口,使用第三方Oauth,但是我陷入了这个弹出窗口,没有办法回到我的应用程序。

So, I can open a pop up inside my app and use third parties Oauth but then I'm stuck inside this pop up and I have no way to return to my app.

我几乎检查了在互联网上可以找到的一切,我绝对不知道该怎么办。

I checked almost everything I could find in the internet and I absolutely don't see how to do now.

我使用cordova.js 3.5 Android版本,并安装了inappbrowser与

I use cordova.js 3.5 Android build , and I install inappbrowser with

cordova plugin add org.apache.cordova.inappbrowser

一切都是标准的,cordova.js正确加载,可以在日志中看到InappBrowser在我调用它时正确使用。

Everything is standard, cordova.js is correctly loaded, and I can see in the logs InappBrowser is correctly used when I call it.

  08-08 16:20:20.594: D/InAppBrowser(8496): target = _blank

Errr ...帮助?

Errr... Help?

:)

推荐答案

我可以找到一种解决方法问题。这是奇怪和有偏见。但是我认为我不是唯一的一个,我在这里写我的解决方案和我可以解决这个bug的方式。

I could find a way to solve this problem. It's weird and biased. But as I see I am not the only one, I'm writing here my solution and the way I could solve that bug.

首先,我添加了另一个监听器: / p>

First, I added another listener :

ref.addEventListener('exit', function(event) 
{
    if (debug) alert('exit');
});

b
$ b

Then, I used the inject script functionality and I called it every 5 seconds;

function  getStateSecondWindow()
{
    ref.executeScript(
        {code: "localStorage.getItem('loginOauth')"},
        function(data)
        {
            alert(data);
        }
    );
}

setInterval(getStateSecondWindow, 5000);

在这个阶段,我可以在日志中看到一些奇怪的东西:第一次调用getStateSecondWindow被阻塞。但是,然后/一切/开始工作。我突然有我所有的事件监听器工作正常。这就像我在某个地方有一个果酱,而executeScript()只是解除了一切。

At that stage, I could see something weird in the logs : the first call to getStateSecondWindow was blocked. But then /everything/ started to work. I suddenly had all my event listeners working correctly. It was like I had a jam somewhere and the executeScript() just unblocked everything.

这个解决方案适用于我的4个项目。

This solution worked for my 4 projects. The behaviour was the same for each of them.

如果事件再次出现问题,我使用双重系统检查我的第二页,并找到一个关闭它的方法在适当的时刻:在第二页,我使用本地存储设置我的值的值:
localStorage.setItem(loginOauth,'OK');

In case the event had problems again, I used a double system to check my second page and find a way to close it at the right moment : in the second page, I used the local storage to set the value of my var : localStorage.setItem( "loginOauth", 'OK');

在我的第一页,我使用执行脚本来读取本地存储:

In my first page, I used the execute script to go to read that local storage :

function getStateSecondWindow() {
        ref.executeScript(
            {code: "localStorage.getItem('loginOauth')"},
            function(data)
            {
                if (data=='OK')
                {
                    //do what I need to do
                    ref.close();
                } 
            }
        );

在这个系统中,我不依赖于(有时不是)触发事件。即使inappBrowser窗口中的页面来自另一个服务器,它也可以工作:因为在第二个窗口中解释javascript,所以我们在原来的localStorage所在的域中(没有crossbrowsing问题)。

With this system, I was not dependent of the (sometimes not) firing event. It works even if the page in the inappBrowser window comes from another server : as the javascript is interpreted in the second window, we are in the same domain where the original localStorage was made (no crossbrowsing problem).

所以这是我可以去考虑inAppBroswer不发射事件,并找到一种方法来关闭第二个窗口,当需要。希望它有帮助:)

So this is how I could go thought the inAppBroswer not firing events and find a way to close the second window when needed. Hope it helps :)

这篇关于不可能关闭inAppBrowser窗口[Solved]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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