如何在Phonegap应用程序中关闭InAppBrowser本身? [英] How to close InAppBrowser itself in Phonegap Application?

查看:174
本文介绍了如何在Phonegap应用程序中关闭InAppBrowser本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Phonegap应用程序,当前正在使用InAppBrowser显示外部页面.在某些外部页面上,我放置了一个关闭按钮,并且我想关闭InAppBrowser本身.因为InAppBrowser显示这些页面,这就是为什么无法直接访问它的引用来关闭它,并且请不要建议我使用ChildBrowser插件.

I am developing Phonegap application and currently i am using InAppBrowser to display external pages. On some of the external pages I place a close button and i want to close the InAppBrowser itself. because InAppBrowser displays these pages that is why the reference of it is not accessed on itself to close it and Please do not suggest me to use ChildBrowser Plugin.

window.close(); //Not Worked for me
or  
iabRef.close();  //Also not Worked for me because iabRef is not accessible on InAppBrowser. It is created on Parent Window

某些Android设备和iOS设备显示完成"按钮以将其关闭.除了iPad以外,还显示完成"按钮.但是对于Android平板电脑,则没有任何按钮可以将其关闭.

Some of the Android device and iOS device display a Done Button to close it. As well as the iPad also display the Done button. but in Case of Android tablet there is not any kind of button to close it.

更新:-

这是我的完整代码:-

var iabRef = null; 
function iabLoadStart(event) {
}
function iabLoadStop(event) {
}
function iabClose(event) { 
    iabRef.removeEventListener('loadstart', iabLoadStart);      
    iabRef.removeEventListener('loadstop', iabLoadStop); 
    iabRef.removeEventListener('exit', iabClose); 
}
function startInAppB() {
    var myURL=encodeURI('http://www.domain.com/some_path/mypage.html');
    iabRef = window.open(myURL,'_blank', 'location=yes');    
    iabRef.addEventListener('loadstart', iabLoadStart);
    iabRef.addEventListener('loadstop', iabLoadStop);
    iabRef.addEventListener('exit', iabClose);
}

推荐答案

这对我有用:

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

当您要关闭它

这篇关于如何在Phonegap应用程序中关闭InAppBrowser本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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