语言

Menu
Sites
Language
Back and menu button

I cannot work back and menu button on the device and emulator.

To do this, I did do that,

document.addEventListener( 'tizenhwkey', function(e) {

if (e.keyName === 'back') {

if ($.mobile.activePage.attr('id') === 'main') {

tizen.application.getCurrentApplication().exit();

} else {

history.back();

}

}

else if (e.keyName === 'menu') {

 }

});

 

How can I fix it? Please let me know.

Thanks 

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

4 回复
Kirill Chuvilin
Try my variant
function init() {
	document.addEventListener('tizenhwkey', function(e) { // assign hardware buttons click event handler
		if(e.keyName == 'back') { // if back button is clicked
			if (location.hash === '' || location.hash === 'mainPage') { // if the main page is active
				tizen.application.getCurrentApplication().exit(); // close the application
			} else { // if not main page is active
				$.mobile.back(); // go to the previous page
			}
		}
	});
}
$(document).bind('pageinit', init); // assign the init function call to the page initialization
Marco Buettner
https://developer.tizen.org/forums/web-application-development/tizen-2.2b-hardware-buttons
Kirill Chuvilin
Thank you!
$.mobile.activePage().attr('id') === 'mainPage'
looks better than my previous
location.hash === '' || location.hash === 'mainPage'
Kirill Chuvilin
Without brackets of course
$.mobile.activePage.attr('id') === 'mainPage'
But it looks more logical to use jQuery's
$.mobile.back();
instead of
history.back();