為什么總是同時打開兩個網頁而點按鈕卻只能關閉一個,哪位大神能幫我看看?代碼如下:
var mywin=window.open("http://www.xianlaiwan.cn");
? ? ?function clk(){
? ? ? ? mywin.close();??
? ? ?}
? </script>
</head>
<body>
? ? <input name="button" type="button" onClick="clk()" value="點擊我,關閉網站" />
</body>
2018-07-14
稍微改動了一下
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
? <script type="text/javascript">
? ? ?var mywin=window.open("http://www.xianlaiwan.cn","_blank","width=600,height=400,top=100,left=0");
? ? ?function clk(x){
? ? ?x.close();
? ? ?}
? </script>
</head>
<body>
? ? ?<input name="button" type="button" onClick="clk(mywin)" value="點擊我,關閉網站" />
</body>
</html>
2018-07-11
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
? <script type="text/javascript">
???? function clk(){
?????? var mywin=window.open("http://www.xianlaiwan.cn");
??????? mywin.close();?
???? }
?????
?</script>
</head>
<body>
??? <input name="button" type="button" onClick="clk()" value="點擊我,關閉網站" />
</body>
</html>
2018-04-26
window.open()方法的作用就是新打開一個窗口,如果你想關閉當前窗口直接用 onClick="window.close",如果是想兩個窗口同時關閉,需要在clk()函數中加一行window.close;