简体   繁体   English

Ionic Inappbrowser 获取退出事件

[英]Ionic Inappbrowser to picking up exit event

My app which is built on ionic has an inapp browser that opens a url.我的基于 ionic 的应用程序有一个可打开 url 的 inapp 浏览器。 This works fine.这工作正常。 I need to identify when and if the user clicks the close/"X" button on it to run a function.我需要确定用户何时以及是否单击其上的关闭/“X”按钮来运行功能。

I have tried the exit eventlistener but it is not fired when the browser is closed.我已经尝试了退出事件监听器,但是当浏览器关闭时它不会被触发。

I have tried the below.我已经尝试了以下。

var ref = window.open($scope.url, '_blank');

then然后

ref.addEventListener('exit', $scope.bclose());
    $scope.bclose = function(){
        alert('Close');
    }

also

ref.addEventListener('exit', function(event) { 
   alert('Browser Closed');
});

I however have a loadstop listener which works fine.但是,我有一个工作正常的 loadstop 侦听器。 Any help is greatly appreciated.任何帮助是极大的赞赏。

Try to use following way.尝试使用以下方式。 It is working fine.它工作正常。

 $scope.openLink = function (url) {

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

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

    }

I am using following cordova inappbrowser version in my config.xml我在我的 config.xml 中使用以下cordova inappbrowser版本

<plugin name="cordova-plugin-inappbrowser" src="https://github.com/apache/cordova-plugin-inappbrowser.git" version="1.4.1-dev" />

try this:- when you open it in _self the state management of the app is handled.试试这个:- 当你在 _self 中打开它时,应用程序的状态管理被处理。

$ scope.openLink = function (url) { $ scope.openLink = function (url) {

    var ref = cordova.InAppBrowser.open(url, '_self', 'location=yes');

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM