[英]Phonegap 3.2.0 android application Back button cutomization for some pages only
[英]disable android back button only on certian pages
我正在開發一個jQuery移動應用程序,它在一個文檔中包含許多頁面。 例如有#welcome,#about等頁面,而我只想在#about頁面處於活動狀態時才禁用android手機上的后退按鈕。 我有這個腳本通過應用程序禁用按鈕
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", function (e) {
e.preventDefault();
}, false );}
在jquery mobile中,$ .mobile.activePage.attr('id')將返回當前活動頁面的ID值。因此在您的情況下,如果當前活動頁面的ID值不等於'about' ,則需要默認的后退按鈕行為。為此,您可以提供以下代碼。
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", function (e) {
//check if the current page is not an about page
if($.mobile.activePage.attr('id')!=="about")
{
//In all other pages except 'about',the normal back button behaviour is exhibited
window.history.back();
}
}, false );}
當您在Android手機上按下后退按鈕時,上面的代碼檢查當前頁面是否不是關於頁面,如果條件為true,則默認后退按鈕行為由代碼window.history.back()給出 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.