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