问题
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