3.打开新的窗口

2018-06-12  本文已影响0人  若愚同学
index.js
//打开新的窗口
function openWin(){
    /**
     * 第一个参数:要打开的url,也可以是相对路径,也可以是url
     * 第二个参数:在什么位置打开新的窗口 _self,在当前页打开,_blank在新的窗口中打开
     * 第三个第四个暂时忽略
     */
    //window.open("index2.html","_self");
    window.open("index2.html","_blank");
}

//关闭 窗口
function closeWin(){
    //IE所有的网页都能关闭,包括本身
    //只能关闭自己打开的网页,非自己打开的不能关闭 Scripts may close only the windows that were opened by it.
    window.close();
}

index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
    
    <button onclick="openWin()">打开窗口</button>
    
    <button onclick="closeWin()">关闭窗口</button>

</body>
</html>
index2.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
    
    <button onclick="openWin()">打开窗口</button>
    
    <button onclick="closeWin()">关闭窗口</button>

</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读