javascript条件不起作用 [英] javascript condition is not working
本文介绍了javascript条件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function IP()
{
var net = new ActiveXObject("wscript.network");
if((net.ComputerName).value="")
{
window.location.href="Welcome.aspx";
return true;
}
else
{
alert(net.UserDomain+': '+net.ComputerName);
alert('SUCCESS')
return true;
}
return false;
}
这是我的功能,当他遇到
错误时,我想重定向网站用户
Microsoft JScript运行时错误:自动化服务器无法创建对象
否则我想提醒成功..
但是我在某些客户端PC上出现错误,页面未重定向...
this is my function i want to redirect the website user when he Got error of
Microsoft JScript runtime error: Automation server can''t create object
else i want to alert with success..
but i m getting error on some client pc and page is not redirected...
is there any sollution?
推荐答案
很可能是与浏览器安全相关的问题.由于您不能依赖客户端,因此我将在服务器端实现此重定向.看来您处于域环境中,因此您可以轻松地在服务器端检查计算机是否为域成员.
但是您可以将其简单地放在try catch块中,如下所示:
It is very likely to be a browser security related issue. Since yo can not rely on the client I would implement this redirection on server side. It looks that you are in a domain environment, thus you can easily check on server side if the computer is domain member or not.
But you can put it simply in a try catch block, like this:
function IP()
{
try
{
var net = new ActiveXObject("wscript.network");
alert(net.UserDomain+': '+net.ComputerName);
alert('SUCCESS');
}
catch ()
{
window.location.href="Welcome.aspx";
return true;
}
return false;
}
function IP()
{
var net = new ActiveXObject("wscript.network");
if((net.ComputerName).value="")
{
window.location.href="Welcome.aspx";
return true;
}
else
{
alert(net.UserDomain+': '+net.ComputerName);
alert('SUCCESS')
return true;
}
// return false; dont use
}
我尝试了这个
i tried this
try
{
var net = new ActiveXObject("wscript.network");
alert(net.UserDomain+': '+net.ComputerName);
alert('SUCCESS');
}
catch(err)
{
window.location.href="Welcome.aspx";
}
成功
这篇关于javascript条件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文