[英]iFrame OnLoad event in IE not firing after Tapestry Zone update
我有一個掛毯區,其中是一個<iframe>
元素。 我想在iframe加載完成后運行一個簡單的JS函數(只是隱藏並啟用一些東西,沒有花哨的地方)。
在chrome和firefox中,它工作正常,但IE 9出現問題。
function afterExportLoad() {
// hide throbber gif
// enable submit button
}
所以,自然地,我試圖像這樣(內聯)將其綁定到iframe
<iframe onload="afterExportLoad()" .../>
通過PrototypeJS
exportFrame.observe('load', afterExportLoad);
通過本地JS
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版本)中工作?
謝謝 :)
所以,我擺弄了一下,得到了這個解決方案:
在功能中添加了瀏覽器檢查
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;
}
}
如果有任何更好的解決方案,請告訴我:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.