2014-05-05 39 views
4

我試圖在inappbrowser關閉時退出我的應用程序。我試圖通過添加一個eventlistener到瀏覽器,然後從那裏..也許像退出(0)什麼的。 但它不工作,警報永遠不會達到。addEventListener('exit')給PhoneGap中的inappbrowser

有人知道爲什麼嗎? 此外,如果您有關於如何在inappbrowser關閉時退出應用程序的更好的想法,請分享。

我正在使用phonegap。

var ref = null; 

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

回答

6

只要使用「_blank」代替「_self」。如果在現有視圖中打開外部源,則「退出」事件不會觸發。

要退出應用程序使用

navigator.app.exitApp(); 

完整代碼:

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'   
      ); 
} 

希望這會幫助你。

0

似乎inappbrowser的loadstop事件不會在_self加載的inappbrowser中被觸發。

相關問題