如何在多页面Web应用程序中实现反向硬件密钥

时间:2015-02-25 05:46:21

标签: web-applications back-button tizen multipage

我对tizen应用程序开发很新。我正在使用Tizen Web UI Builder开发多页面应用程序。如何实现硬件返回键以返回上一页? 我已经尝试过使用它了。

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 个答案:

答案 0 :(得分:2)

请尝试下面的代码,它会起作用:

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