addEventListener('exit')在PhoneGap中的inappbrowser

时间:2020-12-30 23:01:18

I'm trying to exit out of my application when the inappbrowser closes. I'm trying to do so by adding a eventlistener to the browser, and then from there.. maybe like exit(0) or something. But it's not working, the alert is never reached.

当inappbrowser关闭时,我试图退出我的应用程序。我试图通过在浏览器中添加一个eventlistener来实现这一点。比如出口(0)或者别的什么。但它不工作,警报从未到达。

Does somebody know why? Also if you have a better idea on how to exit the app when the inappbrowser closes, please share.

有人知道为什么吗?如果你对inappbrowser关闭时如何退出应用程序有更好的想法,请分享。

I'm using phonegap.

我使用phonegap。

var ref = null;

ref = window.open('http://google.com', '_self', 'location=no');
ref.addEventListener('exit', function(event) { alert("hello");});

2 个解决方案

#1


6  

Just use "_blank" instead of "_self". The 'exit' event wont fire if external source opened in the existing view.

只需使用“_blank”而不是“_self”。如果在现有视图中打开了外部源,则“退出”事件不会触发。

To exit the app use

退出应用程序使用

navigator.app.exitApp();

Complete code:

完整的代码:

 var ref = window.open('http://google.com', '_blank', 'location=no');

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

 function Exit(){
              navigator.notification.confirm(
                'Do you want to exit app?',  
                function(i){
                    if(i==2)
                     {
                       navigator.app.exitApp(); //This will Close the App
                     }
                },              
                'App Name',            
                'Cancel,Exit'          
              );
 }

Hope this will help you.

希望这能对你有所帮助。

#2


0  

It seems to the loadstop event for inappbrowser doesn't get fired in a _self loaded inappbrowser either.

在_self加载的inappbrowser中,inappbrowser的loadstop事件似乎也不会被触发。

#1


6  

Just use "_blank" instead of "_self". The 'exit' event wont fire if external source opened in the existing view.

只需使用“_blank”而不是“_self”。如果在现有视图中打开了外部源,则“退出”事件不会触发。

To exit the app use

退出应用程序使用

navigator.app.exitApp();

Complete code:

完整的代码:

 var ref = window.open('http://google.com', '_blank', 'location=no');

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

 function Exit(){
              navigator.notification.confirm(
                'Do you want to exit app?',  
                function(i){
                    if(i==2)
                     {
                       navigator.app.exitApp(); //This will Close the App
                     }
                },              
                'App Name',            
                'Cancel,Exit'          
              );
 }

Hope this will help you.

希望这能对你有所帮助。

#2


0  

It seems to the loadstop event for inappbrowser doesn't get fired in a _self loaded inappbrowser either.

在_self加载的inappbrowser中,inappbrowser的loadstop事件似乎也不会被触发。