在IE8 / IE9中的HTML框架之间共享JS对象 [英] Sharing JS objects between HTML frames in IE8/IE9

查看:92
本文介绍了在IE8 / IE9中的HTML框架之间共享JS对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将支持IE8 / IE9的应用程序专门为IE6构建,并使用HTML框架(框架集)。应用程序有很多使用navigator.PropertyABC的JavaScript代码。这里的PropertyABC是一个在一个帧中初始化的对象,并在许多其他帧中使用。这在IE6中起作用,因为导航器对象似乎是在所有帧之间的IE6中共享的。它也适用于IE7兼容模式。但它在IE8 / IE9中不起作用。
有框架嵌套到其他框架,所以它是多层次的。
示例代码:

 < html> 
< frameset rows =50%,50%>
< frame name =asrc =frame1.html>
< frame name =bsrc =frame2.html>
< / frameset>
< / html> b


$ b $ frame $ > < HTML>
< body>
< script type =text / javascript>
navigator.testingSharedVariable =第一帧!;
< / script>
< / body>
< / html>

frame2.html:

 < HTML> 
< body>
< input type =buttononclick =alert(navigator.testingSharedVariable)>
< / body>
< / html>

点击IE6中的按钮时 - 使用第一帧!被提出。在IE8 / IE9 - 未定义。



还有什么我可以用来在框架之间共享对象而不是导航器?
其他浏览器支持并不是必需的,只需要IE8 / IE9。使用标准全局对象 - <$ c <$ c $> 解析方案 $ C>窗口
。在你的情况下,共享的全局对象将是 window.top (这是一个窗口本身)。


I have to bring support for IE8/IE9 to an application which was built specifically for IE6 and uses HTML frames (framesets) a lot. Application has a lot of JavaScript code where "navigator.PropertyABC" is used. Here "PropertyABC" is an object initialized in one of frames and used in many other frames. This worked in IE6 because "navigator" object seems to be shared in IE6 between all of the frames. It also works with IE7 compatibility mode. But it does not work in 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:

<html>
  <body>
    <script type="text/javascript">
        navigator.testingSharedVariable ="1st frame!";
    </script>
  </body>
</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!" is raised. On IE8/IE9 - "undefined".

Is there anything else I could use to share objects between frames instead of "navigator"? Other browser support is not required, just IE8/IE9.

解决方案

Use the standard global object – window. In your case the shared global object would be window.top (which is a window itself).

这篇关于在IE8 / IE9中的HTML框架之间共享JS对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆