Skip to content

Instantly share code, notes, and snippets.

@boyofgreen
Last active June 9, 2016 15:55
Show Gist options
  • Save boyofgreen/1a3409bfc11612aea773 to your computer and use it in GitHub Desktop.
Save boyofgreen/1a3409bfc11612aea773 to your computer and use it in GitHub Desktop.
Back Button All code samples
/**here we are generating a back button in the title bar of the app. it doesn't change the page at all as it is above (or below on phone) the app itself. This is a Windows API ***/
//this is the windows apis for the back button as well as an event handleere for it
var systemNavigationManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
var systemNavigation = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
//this code block adds the page listener that determs if the button should be shown
//this is the windows apis for the back button as well as an event handleere for it
var systemNavigationManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
var systemNavigation = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
//if it is either of these two URLs we don't want to show the back button, we are essencially home
var homeURL = 'https://your.ownsite.com/';
var catURL = 'https://your.ownsite.com/categories';
var curURL = window.location.href;
//set up event to show if it should be shown
window.addEventListener('load', function(){
if (curURL !== homeURL || curURL !== catURL) {
systemNavigation.appViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.visible;
}
else{
systemNavigation.appViewBackButtonVisibility = Windows.UI.Core.AppViewBackButtonVisibility.collapsed;
}
});
};
/**here we are generating a back button in the title bar of the app. it doesn't change the page at all as it is above (or below on phone) the app itself. This is a Windows API ***/
//here we show how we add a listener that goes back through the history stack when the button is hit
//this is the windows apis for the back button as well as an event handleere for it
var systemNavigationManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
var systemNavigation = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
systemNavigationManager.addEventListener("backrequested", handleSystemNavigationEvent.bind(this));
// function to handle the system Navigation Event
function handleSystemNavigationEvent(args) {
history.back()
}
//finally add the line that blocks the default back button on tablets and phones
// function to handle the system Navigation Event
function handleSystemNavigationEvent(args) {
args.handled = true;
history.back()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment