0

誰か助けてください。

以下のようなiframeを作成するJS(以下のtarget.js)を作成しました。

原因はわかりませんが、IE9,8でオンロード機能が動作しません。

script タグを削除すると、onload 関数が機能し、ウィンドウがスクロールして固定されました。

<body onload="location.hash='#hashparam';">

HTML

<!-- Target part -->
<script params="parameters" src="target.js"></script>
<iframe src="target.html?parameters">
    <html>
       <head>
       </head>
       <body>
          <script src="target-inner.js"></script>
          many iframes which are made by the script tags
       </body>
    </html>

HTML

</body>

誰かが原因を知っていますか?ご存知でしたらご教授願います。


// target-inner.js
isIE = /MSIE/.test(window.navigator.userAgent);
isIE10 = /MSIE 10/.text(window.navigator.userAgent);
if (isIE10 || !isIE) {
    doc.clear();
    doc.open;
}
doc.write("<html><head></head><body>");
doc.write(text);
doc.write("</body></html>");
if (isIE10 || !isIE) {
    return doc.close();
} else {
    return;
}
4

1 に答える 1

0

原因がわかりました。

IE9 では、iframe は本文のオンロード機能をブロックします。そして、私のスクリプトには IE9 の document.close() がありません。そのため、onload 関数は永久にブロックされます。しかし、私のスクリプトでは、IE9 で document.write の後に document.close() を追加すると、IE9 がクラッシュします。そこで実装方法を変更し、本体のonload部分にmain関数を追加しました。できます。

fmodos様、ご丁寧にありがとうございます。

于 2013-05-20T00:42:03.017 に答える