当我在 javasacript 中使用“windows.location.href”时,出现"Components.Exception("prompt aborted by user", Cr.NS_ERROR_NOT_AVAILABLE)" 异常。我的代码是:
function checkCookie(){
var value = null;
var cookieName='UserDetailsCookie';
value=ReadCookie(cookieName);
if(value != null){
var url='<%=request.getContextPath()%>/jsp/admin.jsp';
window.location.href = url;
}
document.loginForm.userName.focus();
}
function ReadCookie(name)
{
name += '=';
var parts = document.cookie.split(/;\s*/);
for (var i = 0; i < parts.length; i++)
{
var part = parts[i];
if (part.indexOf(name) == 0)
return part.substring(name.length);
}
return null;
我在 body 的 onLoad 事件上调用这个方法
<body onLoad="javascript:checkCookie();">
有人知道为什么会抛出这个异常吗?
最佳答案
我不是 100% 确定,但我认为这是由于线路造成的
document.loginForm.userName.focus();
因为这将取消使用 window.location.href = 'xxx' 完成的 URL 加载。
无论如何,一般来说,在设置 location.href 属性后不应该有任何代码行。
希望有帮助,我知道它已经过时了,但我回答了 moomoochoo,因为他的评论不是“那么”旧。
关于javascript - 获取 "prompt aborted by user"javascript 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8211225/