impossible to close inAppBrowser window

…衆ロ難τιáo~ 提交于 2019-12-01 00:47:13

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.

First, I added another listener :

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

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

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.

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

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

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).

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 :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!