Archivi Blog

How to disable history back browser navigation (english)

During my work experience, I have faced a problem overestimated by many developers, the entropic behavior of final users.

Here you are a simple example javascript code to prevent the use of history back on browser navigation.

Enter the following script in the HEAD tag and you’re done

<script type = “text/javascript”>
var changeHashOnLoadTimeout;
var changeHashAgainTimeout;
var = storedHash window.location.hash;
changeHashOnLoad function () {
var = poundIdx window.location.href.indexOf (“#”);
if (poundIdx == -1) {
window.location.href + = “#”;
}
/ / avoid loop ie
storedHash = window.location.hash;
changeHashOnLoadTimeout = setTimeout (changeHashAgain, 50);
}

changeHashAgain function () {
window.location.href + = “1”;
}

changeHashAgainTimeout window.setInterval = (function () {
if (window.location.hash! = storedHash) {
window.location.hash = storedHash;
}
}, 50);

if (window.attachEvent) {
window.attachEvent (‘onload’, changeHashOnLoad);
} else if (window.addEventListener) {
window.addEventListener (‘load’, changeHashOnLoad, false);
else {}
document.addEventListener (‘load’, changeHashOnLoad, false);
}
</ script>

You can test the example of

http://www.zupersite.com/sample/block-history.htm

The script works for Firefox, Google Chrome, Safari and Internet Explorer 8 and above

comparison between browsers

if browsers were guns then …

Annunci

How to disable history back browser navigation

Durante la mia esperienza lavorativa mi è capitato di affrontare un problema sottovalutato da molti sviluppatori, ovvero il comportamento entropico dell’utente finale (il cosiddetto utonto).

Ecco un esempio semplice codice javascript per impedirgli di utilizzare il tasto back del browser

Inserite nel tag HEAD il seguente script ed il gioco è fatto

<script type = “text/javascript”>
var changeHashOnLoadTimeout;
var changeHashAgainTimeout;
var storedHash = window.location.hash;
function changeHashOnLoad() {
var poundIdx = window.location.href.indexOf(“#”);
if(poundIdx==-1){
window.location.href += “#”;
}
//avoid loop ie
storedHash = window.location.hash;
changeHashOnLoadTimeout = setTimeout(changeHashAgain, 50);
}

function changeHashAgain() {
window.location.href += “1”;
}

changeHashAgainTimeout = window.setInterval(function(){
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);

if (window.attachEvent) {
window.attachEvent(‘onload’, changeHashOnLoad);
}else if (window.addEventListener) {
window.addEventListener(‘load’, changeHashOnLoad, false);
}else {
document.addEventListener(‘load’, changeHashOnLoad, false);
}
</script>

Potete testare l’esempio su

http://www.zupersite.com/sample/block-history.htm (seguite le istruzioni)

Lo script funziona per Firefox, Google Chrome, Safari ed Internet Explorer 8 e versioni superiori.

comparison between browsers

if browsers were guns then …