How to implement back hardware key in multipage webapp in tizen

情到浓时终转凉″ 提交于 2019-12-13 00:30:40

问题


I am pretty new to tizen app development .I am developing a multipage app using Tizen Web UI Builder. How can I implement hardware back key for going back to previous page? I have already tried using this.

document.addEventListener('tizenhwkey', function(e) {
var activePage = $.mobile.activePage().attr('id'); // read current page
switch(e.keyName)
{
case 'back':
    switch(activePage)
    {
        case 'page1':
            tizen.application.getCurrentApplication().exit();
            break;
        default:
            parent.history.back();
            break;
    }
    break;
case 'menu':
    switch(activePage)
    {
        case 'page2':
            console.log('you are on '+activePage);
            break;
        default:
            //TODO: Do something
            break;
    }`enter code here`
break;
}});`

回答1:


Please try out the below code , it will work :

window.addEventListener('tizenhwkey', function(e) {
  var activePage = $.mobile.activePage.attr('id');
  switch (e.keyName) {
  case 'back':
    switch (activePage) {
    case 'page1': // use your first page or another page where the application should close if the use press back
      tizen.application.getCurrentApplication().exit();
      //tizen.application.getCurrentApplication().exit();
      break;
    case 'page2':
      window.history.back(history);
      break;
    case 'page3':
      window.history.back(history);
    default: // if no case available, the back button returns back to previous page
      console.log("Do something");
      //$.mobile.back();
    }
    break;
  }
});


来源:https://stackoverflow.com/questions/28712042/how-to-implement-back-hardware-key-in-multipage-webapp-in-tizen

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