0

Currently

  window.onbeforeunload = function() {

fires every time i exit the page, is it possible to get the requested window.location from a link and if the URL is not the value of a variable run the window.onbeforeunload = function().

James Kirkby
  • 1,716
  • 5
  • 24
  • 46
  • 1
    It's not possible. See: http://stackoverflow.com/questions/1686687/how-can-i-get-the-destination-url-in-javascript-onbeforeunload-event – ahren Nov 18 '13 at 12:52
  • 1
    ... Unless perhaps instead of using the `onbeforeunload` event, you bind to `a` elements and check their `href` attribute. – ahren Nov 18 '13 at 12:53

2 Answers2

0

You can attach the onbeforeunload if the loaded url is not equal to variable. But you cant oprevent the attached function's execution

<script type="text/javascript">
if(window.location.href!=myvar)
{
 window.onbeforeunload=function(){};
}

</script>
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120
0

ahren is right here

function experiment() {

  experimentEnviroment();
  $('a').click(function(){

    var regestedPage = $(this).attr("href");
    var myvar = "bsc.html"

        if( regestedPage != myvar ) {
            $(this).bind('ready',windowUnload());
        }

  });
 }
James Kirkby
  • 1,716
  • 5
  • 24
  • 46