想要關閉當前頁怎么寫?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>close()</title>
? <script type="text/javascript">
? ? ?
? ? ?function ni(){
? ? ? ? ?var s=confirm("確定打開網址么?");
? ? ? ? ?if(s==true){
? ? ? ? ? ?window.open("http://www.xianlaiwan.cn/code/413");
? ? ? ? ?}
? ? ? ? ?else{
? ? ? ? ? ? ?window.close();
? ? ? ? ?}
? ? ? ? ?}
? </script>
</head>
<body>
<input type="button" value="打開網址" onClick=ni();>
</body>
</html>
2016-11-10
同學不得不說,你提的問題非常好,但就是太糾結了,大家都是初學嘛,有很多有疑問的東西也很正常,要不你可以試試獲取他當前的一個狀態,使用if語句判斷它當前觸發的狀態,比如如果為true的時候怎么樣,false的時候怎么樣?關閉當前頁面直接這樣寫就好啦:window.close();這個方法在之前的章節里面有講過哦,同學可能沒留心注意吧!
2016-11-10
同學這是我寫的,你可以參考一下? !
<!DOCTYPE html>
<html>
<head>
? ?<title> new document </title>
? ?<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
? ?<script type="text/javascript">
? ? ? ?// 新窗口打開時彈出確認框,是否打開
? ? ? ?// 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? ? ?//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? ? ?var g_Open=""; //全局變量
? ? ? ?function openWindow(){
? ? ? ? ? ?var judge = confirm('是否要打開邪惡的網站?') //提示框提示
? ? ? ? ? ?var InputText=document.getElementById('Text');//獲取提示框輸入的值
? ? ? ? ? ?if(judge==true){ //判斷當前點擊“確認”按鈕則進入輸入框
? ? ? ? ? ? ? ?g_Open=prompt("請先輸入這個邪惡的地址:http://www.xianlaiwan.cn") //提示當前用戶所輸入的網址
? ? ? ? ? ? ? ?if(InputText.value!="http://www.xianlaiwan.cn"){ //判斷當前輸入框所輸入的網址是否有誤
? ? ? ? ? ? ? ? ? ?alert('你輸入的網址有誤,請重新輸入!'); //如果錯誤則彈出該提示
? ? ? ? ? ? ? ? ? ?g_Open=prompt("請先輸入這個邪惡的地址:http://www.xianlaiwan.cn") //用戶回到輸入界面,重新輸入網址
? ? ? ? ? ? ? ?}else if(InputText.value=="http://www.xianlaiwan.cn"){ //網址正確,則跳轉到該頁面
? ? ? ? ? ? ? ? ? ?window.open(g_Open,'_black,windth=400px,height=500px,menubar=no,toolbar=no');
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?else{ //判斷當前點擊“取消”按鈕則彈出提示
? ? ? ? ? ? ? ?alert('很遺憾,你將失去這五彩繽紛的世界!');
? ? ? ? ? ?}
? ? ? ?}
? ?</script>
</head>
<body>
<input type="button" value="新窗口打開網站" onclick="openWindow()" id="Text" />
</body>
</html>