2017-04-18 33 views
0

嗨,这是我的第二个问题,我会尝试解释。这是一个关闭窗口3秒后,我想要新窗口english.html应该出现的代码。谢谢在同一个标​​签中3秒后打开一个新窗口

<html> 
<head> 
<script> 
function loaded() 
{ 

window.setTimeout(CloseMe, 3000); 
} 

function CloseMe() 
{ 
    window.close(); 
} 
</script> 
</head> 
<body onLoad="loaded()"> 
Hello! 
</body> 
+0

'function CloseMe(){location ='yourNewPage.php'}'。只需将'yourNewPage.php'更改为您想要打开的页面。 – PHPglue

回答

2

对于除用户交互以外的任何内容,您都无法打开一个新窗口。 “页面加载后三秒钟”不是用户交互,因此将被HTML规范要求的所有现代浏览器实现的标准弹出窗口阻止规则阻止。

尝试重定向用户,或者更好,不要:完全跳过第三页。如果有什么东西值得向用户展示,那么值得向用户展示,直到他们点击链接。这样,你知道他们没有把注意力集中在另一个标签上,而你的内容却被未被注意到的东西吸引了。

0

下面是如何实现你想要的一个简单的例子:

//<![CDATA[ 
 
// external.js 
 
var doc, bod, htm, C, E, T; // for use on other loads 
 
addEventListener('load', function(){ // load start 
 

 
// I threw in a few goodies to study - it will help you later 
 
doc = document; bod = doc.body; htm = doc.documentElement; 
 
C = function(tag){ 
 
    return doc.createElement(tag); 
 
} 
 
E = function(id){ 
 
    return doc.getElementById(id); 
 
} 
 
T = function(tag){ // returns an Array of Elements by tag name 
 
    return doc.getElementsByTagName(tag); 
 
} 
 
// notice that `window` is implicit, so you don't actually need to use it to access its properties 
 
setTimeout(function(){ // unexecuted functions and Anonymous functions behave the same 
 
    location = 'https://www.w3.org'; // it's really this easy to set the `window.location.href` 
 
}, 3000); 
 

 
});// load end
/* external.css */ 
 
html,body{ 
 
    padding:0; margin:0; 
 
} 
 
.main{ 
 
    width:980px; margin:0 auto; 
 
}
<!DOCTYPE html> 
 
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> 
 
    <head> 
 
    <meta http-equiv='content-type' content='text/html;charset=utf-8' /> 
 
    <link type='text/css' rel='stylesheet' href='external.css' /> 
 
    <script type='text/javascript' src='external.js'></script> 
 
    </head> 
 
<body> 
 
    <div class='main'> 
 
    <div>Just a very simple example</div> 
 
    </div> 
 
</body> 
 
</html>

注:你应该练习使用外部资源,使他们可以被缓存。只要确保你改变了你后来改变的任何资源的文件名和路径。

相关问题