I am doing an MVC 6 Application.
I have a primary Menu in _layout
Page. Every Manu has a Landing page, and I can navigate throughthat pages.
I use a function to detect the browser's Back button and I can catch the event before returning to the previous page and being able to redirect to another page or do some other thing.
This is the function I have in all the pages
var backButtonHandler = 'SearchResult';// change name for every page
var backHandledSearchResult = false;
$(function () {
if (window.history && window.history.pushState) {
window.history.pushState('', null, './');
$(window).on('popstate', function () {
if (backButtonHandler == 'SearchResult' && !backHandledSearchResult) {
backHandledSearchResult = true;
BackToView();
}
}
});
}
});
So every time I click Back button, the function BacktoView() is executed.
The problem I have is that when I click the different options of the Primary menu, the popstate
does not change so I can not catch the Browser Back button and do whatever I need.
Every Main Option menu, when it is clicked has it own Landing Page.
The only thing I found to add in that landing pages, reading all the post is this
if (window.performance && window.performance.navigation.type == window.performance.navigation.TYPE_BACK_FORWARD) {
//do something
}
But this is executed after the Landing Page is reloading. I need a way to make popstate
works when the URL does not change, or something similar.
Any Idea how can I make it work?
thanks