页面卸载时,出现我不想要的确认框

When page unload, a confirm box appear I don't want

本文关键字:我不想 确认 卸载      更新时间:2023-09-26

我正在制作这样的聊天程序:http://www.webengine.co.kr/wechat?l=en(韩国网站),我有一个像标题这样的问题。(有时会出现此问题。如果要对此进行测试,请多次刷新页面。

我认为这个问题是由我的 ajax 脚本引起的

function wechat(id, chatroom_srl, last_chatline_srl, key, nick_name){
  this.id = id;
  this.chatroom_srl = chatroom_srl;
  this.last_chatline_srl = last_chatline_srl;
  this.key = key;
  this.nick_name = nick_name;
  this.wechat = $("#"+this.id);
  var oWechat = this.wechat;
  function exec_json_nomsg(a,b,c){
    if("undefined" == typeof b) b = {};
    a = a.split(".");
    if(2 == a.length){
      $.extend(b, {module:a[0],act:a[1]});
      if("undefined" != typeof xeVid) $.extend(b, {vid:xeVid});
      $.ajax({
        type:"POST",
        dataType:"json",
        url:request_uri,
        contentType:"application/json",
        data:$.param(b),
          success:function(a){
          if($.isFunction(c)) c(a);
        }
      });
    }
  }
  function procChatLines(data){
    for(i=0;i<data.chatline_list.length;i++){
      appendLine(data.chatline_list[i].nick_name, data.chatline_list[i].content, data.chatline_list[i].key);
      wechat.last_chatline_srl = data.chatline_list[i].chatline_srl;
    }
    wechat.timer = setTimeout(loadChatContents, 100);
  }
  function loadChatContents(){
    exec_json_nomsg("chat.loadChatContents", {chatroom_srl:wechat.chatroom_srl, last_chatline_srl:wechat.last_chatline_srl, key:wechat.key}, procChatLines);
    clearTimeout(wechat.timer);
  }
  function appendLine(nick_name, content, key){
    var lineObj = $("<div class='"chatLine'"></div>");      
    if(wechat.key == key) lineObj.addClass("chatMe");       
    lineObj.html("<span class='"chatNickBold'">"+nick_name+" : </span>"+content);
    oWechat.find(".chatContentHeight").append(lineObj);
    scrollDown();
  }
  function scrollDown(){
    var o = oWechat.find(".chatContent");
    o.stop().animate({scrollTop:o.find(">.chatContentHeight").height()-o.height()}, 300, "easeInOutQuart");
  }
  $(window).load(function(){
    scrollDown();
  });   
  oWechat.find(".wechatInput").keydown(function(e){
    if(e.keyCode == 13){
      if($(this).val().trim() != ""){
        exec_json_nomsg("chat.procChatInsertChatLine",{"chatroom_srl":wechat.chatroom_srl,"content":$(this).val()});
        appendLine(wechat.nick_name, $(this).val(), wechat.key);
        $(this).val("");
      }
    }
  });
  wechat.timer = setTimeout(loadChatContents, 100);
}
  new wechat("wechat1", 1, [last_chatline_srl(PHP give this)], "[User Hidden Key(PHP give this)]", "[User Nick Name]");

我该怎么做才能解决此问题?

看来你的语法有点错误。您缺少一个额外的支架。这就是它应该的样子。

$.ajax({
    type:"POST",
    dataType:"json",
    url:request_uri,
    contentType:"application/json",
    data:postData,
    success:function(b){
        if(0 < b.error){
            //we get to here if b.error is < 0. 
            alert(b.message);
        }
        else{
            call_back_function();
        }
    }
});

您的问题不在于您发送的脚本,在您指向的网站上,您正在使用 srchat 上的小部件.js文件第 648 行和第 649 行您有:

window.onbeforeunload = function(){if(!chtisbk && chtunload == 'Y') {if(dallar('cht_gout').value == '0'){if(cht_go('out')){dallar('cht_gout').value = '9';if(navigator.appName == 'Opera') alert('접속을 종료합니다');}}}}
window.onunload = function(){window.onbeforeunload();}

这两行负责该消息。

您也在使用此库 common/js/xe.min.js在此库上,当启动 AJAX 调用时,它将显示该消息,直到调用返回值。如果要修改,则需要该文件的源。