在加载的特定页面上执行功能 [英] Execute a function on specific page loaded
问题描述
我只想运行一个函数,只有当我在我的网站的特定部分,并且一旦我离开网站的那一部分,我想要退出该功能。我已经试过这样做了。
window.onload = carousel();
但是,一旦网站的任何页面加载,而不是我想要的特定页面 page3.html
)。
只能使用html,css和javascript。没有外部库和类似的
使用 window.location
。然后将其包装到函数中,并将其分配给 onload
事件: > window.onload = function(){
if(window.location.href.indexOf('page3.html')> -1){
carousel();
}
}
I want to run a function only and only when I'm on a specific part of my website and once I leave that part of the website I want to go out of that function. I've tried to do so with
window.onload = carousel();
But this will happen once the any page of the website loads and not the specific one I want to (page3.html
).
Only using html, css and javascript. No external libraries and such
Check the url by using window.location
. Then wrap that inside a function and assign it to your onload
event:
window.onload = function() {
if (window.location.href.indexOf('page3.html') > -1) {
carousel();
}
}
这篇关于在加载的特定页面上执行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!