admin管理员组文章数量:1318580
I'm having a little difficulty opening up windows after a period of time, and then closing them after a period of time, automatically. I'm not sure why, but it seems like when I try to use setTimeout on a window.open and window.close they interfere somehow. Here is my code atm:
function topLeft() {
var myWindow = "image.png", "ONE", "width=300,height=310,top=100,left=100,menubar=no,toolbar=no,titlebar=no,statusbar=no";
setTimeout(function() {
myWindow.window.open() }, 5000);
setTimeout(function() {
myWindow.close() }, 10000);
function start() {
openClose();
}
window.onload = start;
Thanks for looking
I'm having a little difficulty opening up windows after a period of time, and then closing them after a period of time, automatically. I'm not sure why, but it seems like when I try to use setTimeout on a window.open and window.close they interfere somehow. Here is my code atm:
function topLeft() {
var myWindow = "image.png", "ONE", "width=300,height=310,top=100,left=100,menubar=no,toolbar=no,titlebar=no,statusbar=no";
setTimeout(function() {
myWindow.window.open() }, 5000);
setTimeout(function() {
myWindow.close() }, 10000);
function start() {
openClose();
}
window.onload = start;
Thanks for looking
Share Improve this question asked May 9, 2015 at 20:26 biscuit_biscuit_ 1971 gold badge3 silver badges17 bronze badges1 Answer
Reset to default 3Your code is just not right.
myWindow
is a string variable.
You're trying to call myWindow.window.open()
. This would generate a script error because myWindow
(a string variable) does not have a window
property.
Perhaps what you mean to do is this:
var myWindowURL = "image.png", myWindowName = "ONE";
var myWindowProperties = "width=300,height=310,top=100,left=100,menubar=no,toolbar=no,titlebar=no,statusbar=no";
var openWindow;
setTimeout(function() {
openWindow = window.open(myWindowURL, myWindowName, myWindowProperties);
}, 5000);
setTimeout(function() {
openWindow.close()
}, 10000);
Popup blockers in most popular browsers will only allow a new window to be opened if it is opened as a result of code running from a direct user action such as a click.
Because a setTimeout()
happens some time in the future, is not considered the direct result of a user action so attempts to open windows from setTimeout()
are likely blocked by the popup blocker.
You can, of course, disable the popup blocker in your own browser, but that is only something you can do in your own browser. You can't disable popup blocking via Javascript (as that would defeat the purpose).
本文标签: javascriptsetTimeout to windowopen and closeon the same windowStack Overflow
版权声明:本文标题:javascript - setTimeout to window.open and close, on the same window? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742045963a2417783.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论