js 中用windows 打开新的页面

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
// 第一种方法,在body里的onunload事件中调用
// function openWin(){
// window.open('https://www.baidu.com');
// }


// // 第二种方法,跟第一种差不多
function closewin(){
window.opener=null;
window.open('index.html');
window.close();
}

// 第三种,在多少秒之后关闭窗口并打开新的页面
function clock(i) { // i为传入几秒
var timer = setInterval(function(){
if(i>0){
document.title= i + "秒后自动关闭本窗口!";
}else{
clearInterval(timer);
closewin();
}
i=i-1;
},1000);
}
//-->
</script>
</head>
<body>
<button onclick="closewin()"> 点击</button>
<button onclick="clock(2)">点击事件</button>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/m0_38044453/article/details/81037660