2014-02-25 56 views
1

我有一個Tapestry區域,其中有一個元素。我想在iframe完成加載時運行一個簡單的JS函數(隱藏並啓用一些東西,沒什麼奇怪的)。IE中的iFrame OnLoad事件在Tapestry區域更新後未觸發

在Chrome和Firefox,它工作得很好,但我有問題與IE 9

function afterExportLoad() { 
    // hide throbber gif 
    // enable submit button 
} 

所以,natually,我試着結合它的iframe像這樣(在線)

<iframe onload="afterExportLoad()" .../> 
經由PrototypeJS

經由本地JS

exportFrame.observe('load', afterExportLoad); 

if (window.addEventListener) { 
    exportFrame.addEventListener("load", afterExportLoad, false); 
} else if (window.attachEvent) { 
    exportFrame.attachEvent("onload", afterExportLoad); 
} else { 
    exportFrame.onload = afterExportLoad; 
} 

使用上面的任何方式,它可以工作在除IE之外的所有內容中,但在IE中,加載iframe之後,gif會「凍結」並且該按鈕仍處於禁用狀態。

有沒有辦法讓它在IE9(也可能是任何其他IE版本)中工作?

謝謝:)

回答

0

所以,我逛了一下襬弄,得到了該解決方案:

function afterExportLoad() { 
    if (document.getElementsByName('downloadFrame').length > 0) { 
     var exportFrame = document.getElementsByName('downloadFrame')[0]; 

     if ((Prototype.Browser.IE && exportFrame.readyState == "complete") || (!Prototype.Browser.IE)) { 
      // my stuff 
     } 
    } 
} 

更改的事件

<iframe onreadystatechange="afterExportLoad();" ...> 

新增的功能瀏覽器檢查

而在監聽區域更新的另一個函數中,iframe爲

if (document.getElementsByName('downloadFrame').length > 0) { 
     var exportFrame = document.getElementsByName('downloadFrame')[0]; 
     if (!Prototype.Browser.IE) { 
      exportFrame.stopObserving('readystatechange', exportLoad); 
      exportFrame.onload = exportLoad; 
     } 
    } 

如果ANY1來了一個更好的解決方案,讓我知道:)