javascript - Check if inappbrowser open or closed - Stack Overflow

In my cordova app I am opening(using InAppBrowser plugin) a webpage in inappbrowser by the following co

In my cordova app I am opening(using InAppBrowser plugin) a webpage in inappbrowser by the following code.

var ref = cordova.InAppBrowser.open('', '_blank', 'location=yes');
ref.close();

Now I want to check if the InAppBrowser is closed(not a particular URL I want to check the browser itself open or closed) in js like ref.isClosed(). But InAppBrowser doesn't facilitate such function. Is there any way to find it?

In my cordova app I am opening(using InAppBrowser plugin) a webpage in inappbrowser by the following code.

var ref = cordova.InAppBrowser.open('http://apache', '_blank', 'location=yes');
ref.close();

Now I want to check if the InAppBrowser is closed(not a particular URL I want to check the browser itself open or closed) in js like ref.isClosed(). But InAppBrowser doesn't facilitate such function. Is there any way to find it?

Share Improve this question asked Oct 5, 2017 at 14:28 jafarbtechjafarbtech 7,0251 gold badge41 silver badges59 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You could just create a simple wrapper to keep track of whether it's open or closed, e.g.:

var iab_controller = (function(){
    var ref, isOpen = false;

    return {
        open: function(url){
            ref = cordova.InAppBrowser.open(url, '_blank', 'location=yes');
            isOpen = true;
            return ref;
        },
        close: function(){
            if(isOpen){
                ref.close();
                ref = null;
                isOpen = false;
            }
        },
        isOpen: function(){
            return isOpen;
        },
        isClosed: function(){
            return !isOpen;
        }
    };

})();

console.log("isOpen: " + iab_controller.isOpen())
console.log("isClosed: " + iab_controller.isClosed())

iab_controller.open('http://apache');

console.log("isOpen: " + iab_controller.isOpen())
console.log("isClosed: " + iab_controller.isClosed())

iab_controller.close();

console.log("isOpen: " + iab_controller.isOpen())
console.log("isClosed: " + iab_controller.isClosed())
var browserRef = cordova.InAppBrowser.open('http://apache', '_blank', 'location=yes');
var isOpen = true;

browserRef.addEventListener('exit', function(event) {
  console.log('exit: event fires when the InAppBrowser window is closed.');
  isOpen = false;
});

Add a listener for an exit event from the InAppBrowser. This will allow you to perform logic or set a variable to manage state.

https://cordova.apache/docs/en/latest/reference/cordova-plugin-inappbrowser/#inappbrowseraddeventlistener

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745581233a4634269.html

相关推荐

  • javascript - Check if inappbrowser open or closed - Stack Overflow

    In my cordova app I am opening(using InAppBrowser plugin) a webpage in inappbrowser by the following co

    17小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信