onBackKeyDown get specific page

允我心安 提交于 2019-12-25 05:08:39

问题


I want to use the backkey @ android phones to go back to some specific page. My code(JS):

function onBackKeyDown() {
    currentId = $.mobile.activePage.attr('id');
    if(currentId == "#swipediv"){
    $.mobile.changePage("#home", "slide", false, true);
    }
    else{
    history.go(-1);
    }
}

HTML:

<div data-role="page" data-theme="a" id="home">
      <div data-role="header"><h1>Test</h1></div>
        <div data-role="content">
          <p>Home</p>
        </div>

      </div>
    </div>

    <div id="swipediv">
        <div data-role="page" data-theme="a" id="1">
            <div data-role="header"><h1>1</h1></div>
            <div data-role="content">
                <p>1</p>
            </div>
         </div>
    </div>

What's wrong ? Any suggestions?

best regards


回答1:


Have you properly added the backbutton listener like this?

    function onDeviceReady() {
        // Register the event listener
        document.addEventListener("backbutton", onBackKeyDown, false);
    }

If yes then you check for the pageid currentId == "#swipediv" should be used without # Like this

currentId == "swipediv"


来源:https://stackoverflow.com/questions/11170456/onbackkeydown-get-specific-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!