简体   繁体   English

如何在特定页面上调用窗口加载事件

[英]How to call window load event on specific page

I want to call windows.load event on specific page. 我想在特定页面上调用windows.load事件。 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. 如果我删除if condition则覆盖在每个页面中显示。 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 ? 如何使它仅针对我的car-driving.html页面,以便如果有人访问car-driving.html页面,则它将显示覆盖?

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" document.URL返回整个URL,例如:“ http://stackoverflow.com/questions/17970734/how-to-call-window-load-event-on-specific-page”

You'll have to use a regex match or indexOf 您必须使用正则表达式匹配或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: 尝试在警报中显示href的值,您将看到需要匹配的内容:

$(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 这是我的弹出式div类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在页面加载Mangento 2之前调用窗口调整大小事件jQuery - How to call window resize event jquery before page load mangento 2 如何在页面加载事件中调用JavaScript函数? - How to call a JavaScript function on page load event? 如何从vb.net中的页面加载事件中调用特定的javascript函数 - how to call a specific javascript function from a set on page load event in vb.net 每当发生事件时,如何每次都可以调用特定页面? - How can I call a specific page everytime than a event occurs? 在页面加载事件中调用Java脚本函数? - Call Java script function in Page load event? 在page_load事件上调用javascript函数 - Call javascript function on page_load event 如何在contentplaceholder的子页面的页面加载事件中调用javascript函数? - How to call javascript function on the page load event of the child page which is in contentplaceholder? 如何为iFrame按钮单击调用window onunload事件,父页面和iFrame位于不同的域中 - how to call window onunload event for iFrame button click where parent page and iFrame resides in different domain 如何解决jquery中的窗口加载事件问题? - How to solve window load event issue in jquery? 如何在特定页面上加载文件? - how to load file on a specific page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM