简体   繁体   English

在IE8 / IE9的HTML框架之间共享JS对象

[英]Sharing JS objects between HTML frames in IE8/IE9

I have to bring support for IE8/IE9 to an application which was built specifically for IE6 and uses HTML frames (framesets) a lot. 我必须将对IE8 / IE9的支持引入到专门针对IE6构建的应用程序中,该应用程序大量使用HTML框架(框架集)。 Application has a lot of JavaScript code where "navigator.PropertyABC" is used. 应用程序具有许多使用“ navigator.PropertyABC”的JavaScript代码。 Here "PropertyABC" is an object initialized in one of frames and used in many other frames. 此处,“ PropertyABC”是在一个帧中初始化并在许多其他帧中使用的对象。 This worked in IE6 because "navigator" object seems to be shared in IE6 between all of the frames. 这在IE6中有效,因为“导航器”对象似乎在IE6中在所有框架之间共享。 It also works with IE7 compatibility mode. 它也可以与IE7兼容模式一起使用。 But it does not work in IE8/IE9. 但是它在IE8 / IE9中不起作用。 There are frames nested into other frames, so it's multi-level. 有些框架嵌套在其他框架中,所以它是多层的。 Sample code: 样例代码:

<html>
  <frameset rows="50%,50%">
    <frame name="a" src="frame1.html">
    <frame name="b" src="frame2.html">
  </frameset>
</html>

frame1.html: frame1.html:

<html>
  <body>
    <script type="text/javascript">
        navigator.testingSharedVariable ="1st frame!";
    </script>
  </body>
</html>

frame2.html: frame2.html:

<html>
  <body>
    <input type="button" onclick="alert(navigator.testingSharedVariable)">
  </body>
</html>

When clicked on a button in IE6 - alert with "1st frame!" 在IE6中单击按钮时-出现“第一帧!”警报 is raised. 被提出。 On IE8/IE9 - "undefined". 在IE8 / IE9上-“未定义”。

Is there anything else I could use to share objects between frames instead of "navigator"? 还有什么我可以用来在框架之间共享对象而不是“导航器”的? Other browser support is not required, just IE8/IE9. 不需要其他浏览器支持,仅需要IE8 / IE9。

Use the standard global object – window . 使用标准的全局对象– window In your case the shared global object would be window.top (which is a window itself). 在您的情况下,共享的全局对象将是window.top (本身就是window )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM