English 中文(简体)
IE打电话两次在经分析的网站
原标题:IE calls functions twice on ajaxified website

I have strange problem for which I can t think of a solution. I have written some Javascript code to load some content through a AJAX call which also does some animation. To make the website functional I use jQuery with History.js. This is the script:

(function (window, undefined) {
    getContent(true); // Function that gets the initial content via AJAX and does some animation
                      // The parameter specifies that the call to the function is onload

    History.Adapter.bind(window, statechange ,function(event){ 
       getContent(); 
    });

    function getContent(onload){
       if(onload == true){
         // Do onload stuff. Only slightly differs from other event calls
         // If there is no state given define default one ie  home 
         alert( onload event triggered ); // For debug purposes
       } else {
         // Do other event stuff
         alert( click event triggered ); // For debug purposes
       }
     }

    somelinks.on( click ,a,function(){ // Setup some eventlisteners that push the state });

})(window);

在支持超文本5历史/国家预报(Firefox, Chrome)的浏览器中,这一作品是徒劳的。 该职能在装载或重载特定轮胎或点击活动中发挥作用。

然而,当我重新上载一页(例如,com/p/test)以及第二台老板(Content)(功能)时,它也发挥了作用(有汇合机)。 因此,在“第纳尔多”中,重载触发了上载事件的警示,但在电子计算机中,触发了上载事件和点击事件的警示。

我需要的是阻碍我制定守则或进行合乎逻辑的检查,以防止独立实体打电话给第二人。 我探讨了类似的问题(关键词:IE、历史、js等),但没有发现。

希望有些人能够帮助我解决这一问题。

最佳回答
(function (window, undefined) {

    var getContentOK = true;

    getContent(true);

    History.Adapter.bind(window, statechange ,function(event){
       getContent(false);
    });

    function getContent(onload){
       if (getContentOK === true) {

           if(onload == true){
               // Do onload stuff. Only slightly differs from other event calls
               // If there is no state given define default one ie  home 
               alert( onload event triggered ); // For debug purposes
           } else {
               // Do other event stuff
               alert( click event triggered ); // For debug purposes
           }

           getContentOK = false;
           setTimeout(function () {
               getContentOK = true;
           }, 500);
       }
     }

    somelinks.on( click ,a,function(){ // Setup some eventlisteners that push the state });

})(window);

这将把<代码>Statechange的事件手稿压缩到每个500个位的getContent()。

通知中,我添加了一些蓝色旗帜,一到ttle,<条码>Statechange eventhandler and one to mimic Youcode>onload changing. firstRun,第一行将输出<条码>true,后一行false

这不是一个很好的解决办法,因为它将“ plugin”号编码发生的情况混为一谈,但我没有这方面的经验,因此我无法说,为什么EE正在发射两场事件。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签