Friday, December 21, 2012

Disable Browser back Button Operation

window.onbeforeunload = function() { return "You work will be lost."; };
            window.history.forward();
    function noBack() { window.history.forward(); }


    <body onload="loadBanks();" oncontextmenu="alert('Due To Security Reason Right Click is Not Allowed');return false;">
========================================================================================================================================

    <script type="text/javascript" language="javascript">
function DisableBackButton() {
window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function(evt) { if (evt.persisted) DisableBackButton() }
window.onunload = function() { void (0) }
</script>
========================================================================================================================================

<body onUnload="noBack()">
<script>
function noBack()
{
window.history.forward(1);
}
</script>
if(history.length>0)
{
history.go(+1)
}

========================================================================================================================================


So on the page that you do not want people to be able to come back to, try this code:

    <body onLoad=”history.go(+1)”>

Or you can try this JavaScript code:

    onLoad=”if(history.length>0)history.go(+1)”

If you’re not having much luck with that, try this out:

    <script language=”javascript”>
    window.history.forward(1);
    </script>

Or even more simply, you can try this:

    <script>
    history.forward();
    </script>

Make sure to put that on the page before the one you want people to remain on. So if a user clicks from Page 1 to Page 2 and you want them to stay on Page 2, add the code to Page 1.

Another trick you can do is to simple replace the previous page in history with the current page. So when they go back, the history page will actually be the same page. You can do that by using:

    location.replace(this)

========================================================================================================================================
window.history.back(0) = window.location
========================================================================================================================================
<script language ="javascript" >
function DisableRightClick()
{
if (event.button == 2)
{
alert("Right Click is not possible Here !")
}

}
.onmousedown=DisableRightClick;

</script >

========================================================================================================================================
/ It works without the History API, but will clutter up the history
var history_api = typeof history.pushState !== 'undefined'

// The previous page asks that it not be returned to
if ( location.hash == '#no-back' ) {
  // Push "#no-back" onto the history, making it the most recent "page"
  if ( history_api ) history.pushState(null, '', '#stay')
  else location.hash = '#stay'

  // When the back button is pressed, it will harmlessly change the url
  // hash from "#stay" to "#no-back", which triggers this function
  window.onhashchange = function() {
    // User tried to go back; warn user, rinse and repeat
    if ( location.hash == '#no-back' ) {
      alert("You shall not pass!")
      if ( history_api ) history.pushState(null, '', '#stay')
      else location.hash = '#stay'
    }
  }
}

========================================================================================================================================
javascript:location.replace(this.href); event.returnValue=false;
========================================================================================================================================
 
 
 
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
<SCRIPT>
function getTag(el,str) {
while ((el!=null) && (str.indexOf(el.tagName + ":")<0))
el = el.parentElement
return el
}

function navigateTo(sURL,target) {
if ((target == '_self') | | (target=="")) {
window.location.replace(sURL);
return false;
}
if (target == '_top') {
top.window.location.replace(sURL);
return false
}
if (target =='_parent') {
parent.window.location.replace(sURL);
return false;
}
if (target == '_blank' | | parent.frames.length < 1) {
window.open(sURL, target);
return false;
}
else {
if (parent.frames[target])
parent.frames[target].location.replace(sURL);
else
window.open(sURL, target);
return false;
}
}

function checkIEClick() {
var el = getTag(event.srcElement,"A:AREA:")
if ((el!=null) && ((el.tagName=="A") | | (el.tagName=="AREA"))) {
event.returnValue = false
navigateTo(el.href,String(el.target).toLowerCase())
}
}

function checkNSClick(ev) {
if (ev.target.href) {
navigateTo(ev.target.href,String(ev.target).toLowerCase())
return false
}

}

if ((document.all) | | (document.layers))
if (document.layers) {
document.captureEvents(Event.CLICK)
document.onclick = checkNSClick
}
else
document.onclick = checkIEClick
</SCRIPT>
[/code]

A little slick redirection:
<BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>
<META HTTP-EQUIV="Refresh" CONTENT="1; <A HREF="http://www.insideDHTML.com/home.asp">" TARGET=_blank>http://www.insideDHTML.com/home.asp"></A>
<SCRIPT>
<!--
var version = parseInt(navigator.appVersion)
// replace is supported
if (version>=4 | | window.location.replace)
window.location.replace("newPage.htm")
else
window.location.href = "newPage.htm"
// -->
</SCRIPT>
The document, <A HREF="newPage.htm">Scott's Home</A> has moved.
[/code]




No comments:

Post a Comment