2014-10-09 41 views
2

如何禁用Android設備後退按鈕點擊PhonegapOpenUI5應用程序?試過這個,但沒有工作:在OpenUI5中禁用設備後退按鈕?

document.addEventListener("deviceready", onDeviceReady, false); 

function onDeviceReady() 
{ 
    document.addEventListener("backbutton", function (e) { 
     e.preventDefault(); 
    }, false); 
} 

回答

0

一般來說,瀏覽器不允許你禁用後退按鈕。這是出於安全性/可用性的原因,因此您不能將用戶鎖定在您的網頁上。因此,在做這件事之前,你需要三思,以確保你確實在試圖幫助你的用戶。

已經有人說,有技術描述here可能適合你。

我個人建議你做正確的事情,而不是禁用後退按鈕,只需處理事件並在應用程序中進行相應的清理。

在SAPUI5你可以使用jQuery來聽導航事件:

// event fired when the user changes the URL, e.g. forward or back navigation 
// you need to implement the handleNavigate handler 
$(window).on("navigate", handleNavigate) 

// event fired when the user tries to close the browser or reload the page 
// you need to implement the handleBeforeUnload handler 
$(window).on('beforeunload', handleBeforeUnload);