Javascript &引用;无法加载http://url 状态:0“;onbeforeunload方法出错
你们谁能帮我找到这个问题吗 我有一个包含客户端js代码的xpage,当您决定离开页面时应该执行它。在客户端js中,您引用一个按钮并自动单击它。此按钮包含一些服务器端js代码,并将标记从文档(“打开人…”更改为“” 问题是,客户端js在除当前IE(10.0.5)之外的所有浏览器中都无法正常工作,并抛出错误:Javascript &引用;无法加载http://url 状态:0“;onbeforeunload方法出错,javascript,xpages,lotus-domino,lotus,Javascript,Xpages,Lotus Domino,Lotus,你们谁能帮我找到这个问题吗 我有一个包含客户端js代码的xpage,当您决定离开页面时应该执行它。在客户端js中,您引用一个按钮并自动单击它。此按钮包含一些服务器端js代码,并将标记从文档(“打开人…”更改为“” 问题是,客户端js在除当前IE(10.0.5)之外的所有浏览器中都无法正常工作,并抛出错误: unable to load http://urlofthedocument/... status:0 有趣的是,当我在click()方法之后插入alert()-方法时,在每个浏览器中都可以
unable to load http://urlofthedocument/... status:0
有趣的是,当我在click()方法之后插入alert()-方法时,在每个浏览器中都可以正常工作。但由于我不想包括这一警告声明,我想一定有不同的东西可以避免这种情况。(短时间暂停而不是警报方法也不起作用。)
我的CS JS代码:
window.onbeforeunload = WarnEditMode;
function WarnEditMode(){
if(needUnloadConfirm == true){
var el = window.document.getElementById("#{id:Hidden4SSJS}");
el.click();
//document.open();
//document.write(el);
//document.close();
//alert("You're about to leave the page");
//pause(5000);
}
}
function pause(millis){
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis)
}
你们能帮我吗?我会使用带有隐藏计算字段的XSP对象(而不是您的特殊按钮)来完成这项工作 大概是这样的:
function WarnEditMode(){
if(needUnloadConfirm == true){
XSP.partialRefreshGet("#{id:unlockDocCF1}", {
params: {
'$$xspsubmitvalue': 'needToUnlock'
},
onComplete: function () {
alert('You are about to leave this page and the document has been unlocked.');
},
onError : function (e) {
alert('You are about to leave this page and the document has NOT been unlocked.\n' + e);
}
);
}
pause(5000);
}
try{
var sval = @Explode(context.getSubmittedValue(), ',');
if (sval == null) return result + " no action.";
if (!"needToUnlock".equals(sval[0])) return result + " no action.";
print("Hidden4SSJS-Button-Test @ Person");
var db:NotesDatabase = database;
var agt:NotesAgent;
var doc:NotesDocument = XPPersonDoc.getDocument()
agt = db.getAgent("(XPUnlockDocument)");
agt.run(doc.getNoteID());
return 'document unlocked.';
}catch(e){
_dump(e);
}
然后,计算字段的javascript如下所示:
function WarnEditMode(){
if(needUnloadConfirm == true){
XSP.partialRefreshGet("#{id:unlockDocCF1}", {
params: {
'$$xspsubmitvalue': 'needToUnlock'
},
onComplete: function () {
alert('You are about to leave this page and the document has been unlocked.');
},
onError : function (e) {
alert('You are about to leave this page and the document has NOT been unlocked.\n' + e);
}
);
}
pause(5000);
}
try{
var sval = @Explode(context.getSubmittedValue(), ',');
if (sval == null) return result + " no action.";
if (!"needToUnlock".equals(sval[0])) return result + " no action.";
print("Hidden4SSJS-Button-Test @ Person");
var db:NotesDatabase = database;
var agt:NotesAgent;
var doc:NotesDocument = XPPersonDoc.getDocument()
agt = db.getAgent("(XPUnlockDocument)");
agt.run(doc.getNoteID());
return 'document unlocked.';
}catch(e){
_dump(e);
}
我已经自己弄到了。您只需使用XSP.error=function(e){window.document.getElementById(“#{id:Hidden4SSJS}”)捕捉代码中的某个地方的错误即可;非常感谢你的帮助。不幸的是,这个解决方案只适用于IE和Firefox,而不适用于Chrome、Safari或Opera。我的点击按钮解决方案也适用于Chrome。我还没有找到一个更好的解决方案,也可以让Opera或Safari开始工作。