1

각 프레임이 분리 된 프레임으로 열리고 상위 창에서 일부 JS API를 사용할 수있는 다중 프레임 응용 프로그램이 있습니다. API 예외 (오류)를 throw 할 수 있지만 iframe에서 catch 할 수 없습니다. IE8에서만 재생산됩니다. IE8/IE9 및 Chrome에서 확인했습니다. 예컨대 :부모 창에서 iframe에서 오류를 catch 할 수 없습니다.

<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> 

iframe.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> 

는 IE 버그인가요
인 test.html? 해결 방법은 무엇입니까?

g_fn = window.frameElement.g_fn; 

을 또는이, iframe의 내부 iframe의가있는 경우 :

답변

0

이 시도

g_fn = top.window.g_fn; 
+0

감사합니다! 도움이되었다. – qshurick

관련 문제