1

マルチフレームアプリケーションがあり、各フォームは別々のフレームで開き、親ウィンドウからJSAPIを使用できます。APIは例外(エラー)をスローできますが、iframeでキャッチできません。IE8でのみ再現されます。IE8/IE9とChromeでチェックしました。例:
test.html

<html>
  <head>
    <script language="JavaScript" type="text/javascript">
      var g_fn = {};
      function onLoad() {
        g_fn.thrown_error = function() {
          throw new Error("Main window: error");
          return 1;
        }
        window.g_fn = g_fn;
      }

      function window_do() {
        try {
          g_fn.thrown_error();
        } catch (err) {
          alert("Error catched!");
        }
      }
    </script>
  </head>
  <body onload="onLoad();">
    <input type="button" value="do smth in window" onclick="window_do();"/>
    <iframe src="/iframe.html" />
  </body>
</html>

iframe.html

<html>
  <head>
    <script language="JavaScript" type="text/javascript">
      var g_fn;
      function onLoad() {
        g_fn = window.parent.g_fn;
      }

      function iframe_do() {
        try {
          g_fn.thrown_error();
        } catch (err) {
          alert("Error catched!");
        }
      }

    </script>
  </head>
  <body onload="onLoad();">
    <input type="button" value="do smth in iframe" onclick="iframe_do();"/>
  </body>
</html>

それはIEバグですか?回避策はありますか?

4

1 に答える 1

0

これを試して:

g_fn = window.frameElement.g_fn;

または、これは、iframesの中にiframesがある場合:

g_fn = top.window.g_fn;
于 2012-08-30T09:40:12.363 に答える