I would like to Disable Back button when user click on logoff for this i delete only cookies of that user not session in my application. And want to disable Back button
This is not exactly your approach, but you may disable the navigation panel of any window using plain javascript. Just set window.menubar
and window.toolbar
visibility to false
as follows,
window.menubar.visible = false ;
window.toolbar.visible = false ;
Update:
Changing the menubar and toolbar visibility of an existing window seems to violate security protocols. (https://developer.mozilla.org/en/DOM/window.menubar)
Therefore the only real way is to open a new window with menubar and toolbar set to "no" in the first place:
window.open(url,name,"menubar=no,toolbar=no[, additional options]",true) ;
If you set the replace argument (the last argument) to true the new window should also inherit the history of the window it was opened in.
Check https://developer.mozilla.org/en/DOM/window.open and http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx for reference.
Use following code as it is:
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function () {
history.pushState('newjibberish', null, null);
};
}
else {
var ignoreHashChange = true;
window.onhashchange = function () {
if (!ignoreHashChange) {
ignoreHashChange = true;
window.location.hash = Math.random();
}
else {
ignoreHashChange = false;
}
};
}
};
This will work, it worked for me as I am dealing with mobile browsers, android and ios.
window.history.forward();
window.onload = function()
{
window.history.forward();
};
window.onunload = function() {
null;
};
you must push your url in pushState and clean the browser history:
try this :
$(document).ready(function() {
window.history.pushState(null, "", window.location.href);
window.onpopstate = function() {
window.history.pushState(null, "", window.location.href);
};
});
Simple logic: move forward when click forward
function preventBack() {
window.history.forward();
}
window.onunload = function() {
null;
};
setTimeout("preventBack()", 0);
Keep this js code in your page it works.
Sunil was correct, but to use jQuery paste the code below into any page that you want to prevent going back too. I tested this in IE 11, chrome and FF, which worked fine.
$(document).ready(function () {
function disableBack() {window.history.forward()}
window.onload = disableBack();
window.onpageshow = function (evt) {if (evt.persisted) disableBack()}
});