[英]Run a script after page loaded without using onload funcion
we use <body onload="f1()">
for doing something onload 我们使用
<body onload="f1()">
来做一些onload
Is there anyway i can run a script f1 function
after a page is loaded fully ?? 无论如何我可以在页面完全加载后运行脚本
f1 function
吗?
Please answer with an example (jsfiddle preferred) 请回答一个例子(jsfiddle首选)
The $(window).load(function() {
event executes a bit later when the complete page is fully loaded, including all frames, objects and images $(window).load(function() {
事件稍后在完整页面完整加载时执行,包括所有帧,对象和图像
Using jQuery 使用jQuery
<script>
$(window).load(function() {
alert( "window loaded" );
f1(); // Your function call
});
</script>
Using Pure JS 使用Pure JS
<script>
window.onload = function() {
alert( "window loaded" );
f1(); // Your function call
};
</script>
<script>
f1();
</script>
add this script before closing body tag ie 在关闭body标签之前添加此脚本即
</body>
You can put your function inside $(window).load(function() { ... });
你可以将你的函数放在
$(window).load(function() { ... });
: :
$(window).load(function() {
f1();
});
Code included inside $( window ).load(function() { ... })
will run once the entire page (images or iframes), not just the DOM, is ready. 包含在
$( window ).load(function() { ... })
将在整个页面(图像或iframe)(而不仅仅是DOM)准备好后运行。
使用以下方法,以便在网页已完全加载所有内容(包括图像,脚本文件,CSS文件等)时加载您的功能。
<body onload="f1()">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.