How to close InAppBrowser itself in Phonegap Application?

情到浓时终转凉″ 提交于 2019-12-01 16:11:16

This worked for me:

var win=window.open( "myurl", "_blank");
win.addEventListener( "loadstop", function(){
       var loop = window.setInterval(function(){
           win.executeScript({
                   code: "window.shouldClose"
               },
               function(values){
                   if(values[0]){
                     win.close();
                     window.clearInterval(loop);
                   }
               }
           );
       },100);
   });

In your called window, simply do:

window.shouldClose=true

When you want to close it

jokeyrhyme

There's a solution provided in this blog post: cross window communication with cordova's inappbrowser

Essentially, you could use executeScript() from the parent window to the InAppBrowser instance over and over (once or twice a second, for example), to check whether a value in the IAB has been set. Pressing the "close" button in IAB could set such a variable.

When the parent window discovers that the variable has been set in the IAB, the parent window uses the IAB reference to close() it.

MIantosca

There is a SO post here that describes how to do this.

You basically have to get a reference to the inapp browser by calling window.open and hook into the loadstop event. In the loadstop event check to see if the url contains a predefined path (like mobile/close - but could be anything) and then call call close.

Here is the post

https://stackoverflow.com/a/15981972/54805

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