請問為什么在輸入網址運行的時候,如何實現按“取消”鍵彈出“結束”?求解!!為什么我的代碼點擊取消鍵還是彈出新的網頁?
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??
? <script type="text/javascript"> ?
? ? function openWindow(){
? ? ? ? var open = confirm("是否打開新網頁?");
? ? ? ?
? ? // 新窗口打開時彈出確認框,是否打開
? ? ? ? if(open==true){
? ? ? ? ? ?var newwindow=prompt("請確定打開或重新輸入網址","http://www.xianlaiwan.cn");
? ? // 通過輸入對話框,確定打開的網址,默認為 http://www.xianlaiwan.cn/
? ? ? ? ? ? if(newwindow==null){
? ? ? ? ? ? ? ? window.open(newwindow,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');?
? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? window.open(newwindow);
? ? ? ? ? ? }
? ? ? ? }
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
? ? ? ? else{
? ? ? ? ? ? alert("結束");
? ? ? ? }
? ? }
? </script>?
?</head>?
?<body>?
?<input type="button" value="新窗口打開網站" onclick="openWindow()" />?
?</body>
</html>
2016-09-24
....因為你給他設置了默認值,就算你不輸入也是http://www.xianlaiwan.cn,你只需要把默認值改為",然后把判斷條件改為"if(newwindow=="")即可
2016-09-24
因為你的代碼中
? if(newwindow==null){
? ? ? ? ? ? ? ? window.open(newwindow,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');?
? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? window.open(newwindow);
? ? ? ? ? ? }
表示提示對話框彈出后,
點擊“取消”返回“null”值執行if條件語句中判斷為真的命令,即下列命令打開窗口window.open(newwindow,"_blank",'width=400px,height=500px,menubar=no,toolbar=no');?
點擊“確定”即返回“http://www.xianlaiwan.cn”并存儲在申明的變量newwindow中執行if條件語句中else后的命令也是打開窗口
?window.open(newwindow);