admin管理员组文章数量:1022688
I open a iframe after the page is fully loaded with this javascript code:
<script>
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
window.onload = loadFrame;
</script>
HTML Code
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /> </iframe>
This works perfect but I have to load this iframe 10 seconds after the page is loaded.
1. wait for window.onload
2. If window.onload is ready, wait 10 seconds more before fire.
I tried:
<script>
window.onload = function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
setTimeout(defframe, 10000)
};
</script>
Without success. Thank you very much
I open a iframe after the page is fully loaded with this javascript code:
<script>
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
window.onload = loadFrame;
</script>
HTML Code
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /> </iframe>
This works perfect but I have to load this iframe 10 seconds after the page is loaded.
1. wait for window.onload
2. If window.onload is ready, wait 10 seconds more before fire.
I tried:
<script>
window.onload = function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
setTimeout(defframe, 10000)
};
</script>
Without success. Thank you very much
Share Improve this question edited Apr 5, 2017 at 7:26 labu77 asked Apr 5, 2017 at 7:10 labu77labu77 8373 gold badges14 silver badges36 bronze badges 2- Why wait 10 seconds? – StackSlave Commented Apr 5, 2017 at 7:30
- Because when the Iframe is loading, its not possible to click any link on the website until the content in the iframe is fully loaded. When the frame load first after 10 seconds. The User is reading and the probability that the user want click a link during the frame is loading is a bit more less. – labu77 Commented Apr 5, 2017 at 8:06
4 Answers
Reset to default 1The simplest way to do this is leave your function as it is, just call it in different way. Please follow below code:: HTML:
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" > </iframe>
JS:
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
window.onload = setTimeout(loadFrame, 10000);
Working JSfiddle code:: https://jsfiddle/rnrztx1d/1/
We have to put code inside the set Time out method.
HTML:
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /> </iframe>
JS
window.onload = function loadDefFrame() {
setTimeout(function () {
loadFrame(); //call your method
},10000)};
Complete Code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<script>
window.onload = function loadDefFrame() {
setTimeout(function () {
loadFrame(); //call your method
},10000)};
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
</script>
<body>
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /></iframe>
</body>
</html>
You can do like this,
window.onload = function loadFrame() {
setTimeout(function(){
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
}, 10000)
};
in window.load you can set up setTimeout function for 10 seconds.
Alternative way,
window.onload = function() {
setTimeout(loadFrame(), 10000);
};
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
}
You need to wrap onload
process in setTimeout
window.onload = function loadFrame() {
setTimeout(function () {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php";
}, 10000);
};
I open a iframe after the page is fully loaded with this javascript code:
<script>
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
window.onload = loadFrame;
</script>
HTML Code
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /> </iframe>
This works perfect but I have to load this iframe 10 seconds after the page is loaded.
1. wait for window.onload
2. If window.onload is ready, wait 10 seconds more before fire.
I tried:
<script>
window.onload = function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
setTimeout(defframe, 10000)
};
</script>
Without success. Thank you very much
I open a iframe after the page is fully loaded with this javascript code:
<script>
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
window.onload = loadFrame;
</script>
HTML Code
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /> </iframe>
This works perfect but I have to load this iframe 10 seconds after the page is loaded.
1. wait for window.onload
2. If window.onload is ready, wait 10 seconds more before fire.
I tried:
<script>
window.onload = function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
setTimeout(defframe, 10000)
};
</script>
Without success. Thank you very much
Share Improve this question edited Apr 5, 2017 at 7:26 labu77 asked Apr 5, 2017 at 7:10 labu77labu77 8373 gold badges14 silver badges36 bronze badges 2- Why wait 10 seconds? – StackSlave Commented Apr 5, 2017 at 7:30
- Because when the Iframe is loading, its not possible to click any link on the website until the content in the iframe is fully loaded. When the frame load first after 10 seconds. The User is reading and the probability that the user want click a link during the frame is loading is a bit more less. – labu77 Commented Apr 5, 2017 at 8:06
4 Answers
Reset to default 1The simplest way to do this is leave your function as it is, just call it in different way. Please follow below code:: HTML:
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" > </iframe>
JS:
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
window.onload = setTimeout(loadFrame, 10000);
Working JSfiddle code:: https://jsfiddle/rnrztx1d/1/
We have to put code inside the set Time out method.
HTML:
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /> </iframe>
JS
window.onload = function loadDefFrame() {
setTimeout(function () {
loadFrame(); //call your method
},10000)};
Complete Code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<script>
window.onload = function loadDefFrame() {
setTimeout(function () {
loadFrame(); //call your method
},10000)};
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
};
</script>
<body>
<iframe id="defframe" frameBorder="0" scrolling="no" src="about:blank" /></iframe>
</body>
</html>
You can do like this,
window.onload = function loadFrame() {
setTimeout(function(){
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
}, 10000)
};
in window.load you can set up setTimeout function for 10 seconds.
Alternative way,
window.onload = function() {
setTimeout(loadFrame(), 10000);
};
function loadFrame() {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php"
}
You need to wrap onload
process in setTimeout
window.onload = function loadFrame() {
setTimeout(function () {
var iframe = document.getElementById("defframe");
iframe.src = "/frame.php";
}, 10000);
};
本文标签: javascriptWindowonload and run after x secondsStack Overflow
版权声明:本文标题:javascript - Window.onload and run after x seconds - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745493488a2153066.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论