The Back/Return button is a mandatory button on the remote control to go back or close the app.
The app may handle the Back/Return key event. If it does handle the Back/Return key, the app MUST handle both VK_BACK and VK_BACK_SPACE to ensure compatibility between legacy and current devices. On the remote control, the key may be marked with "Back", "Return" or similar. The Back/Return key should provide the user with typical back navigation, and finally, an exit path via window.close(); to leave the app and return to the previous screen.
document.addEventListener('keydown',function (e) { /* Handling keydown event */ case VK_BACK: if(e.keycode == VK_BACK || e.keycode == VK_BACK_SPACE) { //Add prevent Default if focus is not on input field if(!isInputfieldFocused()) { e.preventDefault(); // Now add your code below to handle BACK key } } }, true); // To detect the focus is in input field or not use below code function isInputfieldFocused() { var activeElement = document.activeElement; if (activeElement && (activeElement.tagName.toLowerCase() === 'input' )) { console.log("focus is in input field"); return true; } else { console.log("focus is not in input field") return false; } }
How to use BACK key:
In case of multi page application : The app should use the historical behavior like window.history.go(-1)
Back Behavior >>
window.history.go(-1)
Clean Exit >>
if (typeof SmartTvA_API!= "undefined") {
SmartTvA_API.exit();
} else {
window.close();
}
In case of single page application : The app should use the hierarchical behavior.
To Exit from app, use window.close() method .
Important Recomendation :
When the back key is pressed at the top level of the application or on-screen exit button (optional) is pressed, the app should follow "Back navigation" section in the "Application Development and UI Guidelines". The app may give a confirmation message when exiting the app. The TV device is to navigate back to the source application that called the application, but there could be exceptions
The app should close the full screen mode when the remote control Back key is pressed during full screen video playback.
NOTE: in case the app consists of showing a full screen video playback only, this requirement is not applicable.
When pressing the remote control back key repeatedly, it should eventually exit the app. The app may give a confirmation message when exiting the app.