简体   繁体   English

带有ie6问题的javascript

[英]javascript with ie6 problem

I have a input button with onclick event : 我有一个带onclick事件的输入按钮:

<input id="bSave" type="button" name="bSave" value=Save 
          onclick="save();window.close();">

here is the save function 这是保存功能

function save(){
              //do some calculation
    calculate();
    //submit a form in this popup window
    document.RCSARiskAssessDimenResultForm.submit();
              //call parent opener to submit another form in parent window
    window.opener.document.RiskControlAssessmentDetailForm.bSave.onclick();
}

In my PC with win7/ie8 , the submition request is sent and finished , there's no problem. 在我的带有win7 / ie8的PC中,子发送请求被发送并完成,没有问题。 But the client environment with xp/ie6 , sometimes(not always) the first submition just wasn't sent. 但是xp / ie6的客户端环境,有时(并不总是)第一个submition就没有被发送。 Seems that window.close() is called or other unknown reason(network delay?). 似乎window.close()被调用或其他未知原因(网络延迟?)。

Any kind of suggestion(information) will be thankful. 任何建议(信息)都会感激不尽。

You should put your window.close() when you are sure your submits are done. 当你确定提交完成后,你应该把你的window.close() Usually in form of a callbacks. 通常以回调的形式出现。 This way you are in control of what happens. 通过这种方式,您可以控制所发生的事情。

Javascript has a single thread and it may look sequential but it is not. Javascript有一个单独的线程,它可能看起来是顺序的,但事实并非如此。 If your submits have a call to a server, or use a setTimeout or setInterval you start to have some asynchronous actions and the next JS statement is called. 如果您的提交调用服务器,或者使用setTimeoutsetInterval则会开始执行某些异步操作,并调用下一个JS语句。

May as IE6 has a more fragile implementation that takes some more time to do something and reveal a problem that you could have as well with other browsers with a slow connection. 可能IE6有一个更脆弱的实现,需要更多的时间来做一些事情,并揭示你可能与其他浏览器连接速度慢的问题。

You will have to use a callback function for this. 您将不得不使用回调函数。

See the following example. 请参阅以下示例。

function celebrate(){
    //your celebrate code here
}


function run(){
    //your run code here
}

function compete(){
    run();
    celebrate();
}

In the above case you will sometimes see that the celebrate would be called before or after the run function due to the nature of the javascript runtime. 在上面的例子中,由于javascript运行时的性质,你有时会看到在运行函数之前或之后调用庆祝。

Celebrating while running is a fail. 跑步时庆祝是失败的。

function run(callbackFunction){
    //your run code here

    //execute the callback
    callbackFunction();
}

function celebrate(){
    //your celebrate code here
}

function compete(){
    run(function(){celebrate();});
}

This makes sure you don't celebrate while running. 这可以确保您在跑步时不庆祝。

Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM