开发者_JS百科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).
精彩评论