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