简体   繁体   中英

How to call window load event on specific page

I want to call windows.load event on specific page. I am doing like this ..

$(window).load(function(){

  if(document.URL == "/car-driving.html")
  {
    overlay.show();
    overlay.appendTo(document.body);
    $('.popup').show();    
    return false;
  }
});

Here I am trying to show overlay based on page load, but its not working. If I remove if condition then overlay is showing in every page. How to make it specific to only my car-driving.html page so that if anyone visit car-driving.html page, then it will show overlay ?

Try

 if (window.location.href.match('car-driving.html') != null) {
   overlay.show();
    overlay.appendTo(document.body);
   $('.popup').show();    
   return false;
  }

Hope It Helps

document.URL returns the whole url ex: "http : / / stackoverflow.com/questions/17970734/how-to-call-window-load-event-on-specific-page"

You'll have to use a regex match or indexOf

edit or better yet

document.location.pathname ==

Try displaying the value of the href in an alert and you will see what you need to match:

$(document).ready(function(){
    alert(window.location.href);
});

Hello i Use this and working well for me

 <script> $(window).load(function() { setTimeout(function() { $('#onload').modal('show'); }, 10000); } function delayer() { window.location = 'Your Desired URL'; } ); </script> 
Here .model is my popup div class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM