views:

22

answers:

0

Hello,

I'm making a website and one part of javascript need to disable browser back button and only on some pages that have specific element on it. Here is the script:

function recallhashcheck()
{
  setTimeout("checkhashb()",50);
}



function checkhashb() {
  if (String(window.location.href).indexOf("#back") != -1) {

    window.location.hash = "#";
    document.location.hash = "#";
    location.hash = "#";


    if ( document.getElementById("ctl00_LeadSiteContent_BackBtn") )
    {
      if ( document.getElementById("ctl00_LeadSiteContent_BackBtn").type == "button" )
      {
        document.getElementById("ctl00_LeadSiteContent_BackBtn").click();
      }
    }

    if ( document.getElementById("ctl00_LeadSiteContent_btnBack") )
    {
      if ( document.getElementById("ctl00_LeadSiteContent_btnBack").type == "button" )
      {
        document.getElementById("ctl00_LeadSiteContent_btnBack").click();
      }
    }
  }
  recallhashcheck();
}



if (document.getElementById("ctl00_LeadSiteContent_BackBtn")||document.getElementById("ctl00_LeadSiteContent_btnBack")||document.getElementById("ctl00_LeadSiteContent_btnCancel")||document.getElementById("ctl00_LeadSiteContent_Cancelbtn")) {

  for ( i = 0; i < 3; i++ ) {

    var randomnumber=Math.floor(Math.random()*110000)

    window.location.hash = "#back_" + randomnumber;
    document.location.hash = "#back_" + randomnumber;
    location.hash = "#back_" + randomnumber;

  }

  window.location.hash = "#";
  document.location.hash = "#";
  location.hash = "#";

  setTimeout("checkhashb()",50);

}

It's working on Firefox and Internet Explorer 8, but not on Internet Explorer 7.

And thing that confuse me the most is that when I download whole page ( In IE7 go to Save as, and then save complete page ), and open in IE7 everything is working okay...

Script is placed at bottom of page, so element must be loaded.

On server is working this way: Second part of this script, that execute with script loading, hash is set to url + #back_, and #. But it looks like setTimeout is not starter, or it's started but have error and it's not restarted again...

I need this very fast to fix.

Thanks.