无法加载http://url状态:0"onbeforeunload方法出错

"Unable to load http://url status:0" error in onbeforeunload-method

本文关键字:quot onbeforeunload 出错 方法 状态 加载 http url      更新时间:2023-09-26

你们谁能帮我找到这个问题?

我有一个包含客户端js代码的xpage,当你决定离开页面时应该执行。在客户端js中,您引用一个按钮并自动单击它。这个按钮包含了一些服务器端js代码,并将标志从文档从("open by…"更改为")

事情是,不知何故,客户端js不工作在所有不同的浏览器,除了当前的IE(10.0.5)和抛出错误:

unable to load http://urlofthedocument/... status:0

有趣的是,当我在click()方法之后插入一个alert()方法时,在每个浏览器中都可以正常工作。但由于我不想包含这个警告语句,我认为必须有一些不同的东西来避免这种情况。(用短暂的暂停代替alert方法也不起作用。)

My CS - JS-Code:

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)
}

这是指按钮,它执行以下SS JS代码,点击后:

try{
    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());
}catch(e){
    _dump(e);
}

你们可以帮我吗?

我会使用带有隐藏计算字段的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);
}

那么computed字段的javascript应该是这样的:

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);
}