Skip to content

Instantly share code, notes, and snippets.

@Gr8Gatsby
Created June 30, 2015 22:20
Show Gist options
  • Save Gr8Gatsby/b2ac40ff7251edd04d31 to your computer and use it in GitHub Desktop.
Save Gr8Gatsby/b2ac40ff7251edd04d31 to your computer and use it in GitHub Desktop.
This Gist shows you how to integrate with the AppTitleBar Back button for Windows 10 JavaScript Apps.
// Hardcoded Navigation Stack
var navigationStack = [
{ "url": "http://www.bing.com" },
{ "url": "http://www.msn.com" }
]
// GoBack function
function goBack() {
var place = navigationStack.pop();
// TODO: Navigate to place.url;
setNavigationState();
}
// Function to set Navigation State
function setNavigationState() {
if (typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.UI.Core !== 'undefined') {
var systemNavigation = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
if (navigationStack.length > 0) {
systemNavigation.appViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.visible;
} else {
systemNavigation.appViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
}
}
}
// function to handle the system Navigation Event
function handleSystemNavigationEvent(args) {
if (navigationStack.length <= 0) {
return;
}
args.handled = true;
goBack();
}
// Initialize the code on Windows load
addEventListener('load', function(){
setNavigationState();
if(typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.UI.Core !== 'undefined') {
var systemNavigationManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
systemNavigationManager.addEventListener("backrequested", this.handleSystemNavigationEvent.bind(this));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment