日期:2014-05-16  浏览次数:20270 次

弹出窗口的简单问题。
var   fileName= " ";

//设置fileName
fileName= "XX.html "                     //该文件不存在

window.open(fileName,   'newwindow ', ' ');


//=============================

问题:
上面的   window.open()函数在被调用时,由于fileName文件不存在,会弹出系统错误提示,如何屏蔽掉这种错误提示。或者在调用之前,如何判断文件有无。

------解决方案--------------------

window.open(fileName, "_blank ", " ");

我用這個測試的結果是:
1 .如果fileName存在,會打開
2.如果不存在,會打開一個空白頁


------解决方案--------------------
有意思的问题,试了试,看看行不,L@_@K

注:IE 6, IIS 5 下测试可用!

<body>
<input type= "button " id= "btnLogin " value= "Login ">
<script language= "JavaScript ">
<!--
var oLogin = document.getElementById( "btnLogin ");
oLogin.onclick = function()
{
var oChildWindow = window.open( "noExistPage.html ");

if (oChildWindow.location.toString().indexOf( "dnserror.htm ") > -1)
{
alert( "页面没找到,弹出页面将被关闭! ");
oChildWindow.close();
}
};
//-->
</script>
</body>