本文介绍了JS Chrome top.document的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Chrome的'top.document',在FF和IE8中都是有效的。

在Chrome中,'top'有效,top.length返回2 (帧)...应该如此。但是top.document返回'undefined'。需要获得一个元素。 top.document.getElementById(id)在FF和IE8中都可以很好地工作。



在此先感谢您,
swk

我知道我的答案迟到了,但这一直让我发疯,而且这个问题似乎对我来说简直就是因为我的页面并没有实际托管。这只是一个铺设在网络文件夹中的原型。如果该页面托管在服务器上,那么它可以正常工作。



甚至更糟糕的是,Chrome在引发安全异常之后不会评估任何内容。我终于弄清楚为什么我看不到任何全局变量。



至少我可以解决第二个问题,在try / catch块中触及顶部,以便任何其他Javascript仍会评估。无论如何,这对我来说就足够了,用于原型。


What is Chrome's equivalent of 'top.document', valid in both FF and IE8.

In Chrome, 'top' is valid, top.length returns 2 (frames)...as it should. But top.document returns 'undefined'. Needed to get an element. top.document.getElementById(id) works perfectly in both FF and IE8.

Thanks in advance,swk

解决方案

I know my answer's late, but this has been driving me crazy, and the issue, it seems for me anyway, is simply because my page wasn't actually hosted. It was just a prototype laying in a network folder. If the page is hosted on a server, it works fine.

What even made it worse, is that Chrome wouldn't evaluate anything after that security exception was thrown. Took me forever to figure out why I couldn't see any of my global variables.

I was able to get around the second issue at least, by surrounding the stuff that touches top in a try/catch block so that any other Javascript would still evaluate. This is enough for me, for prototype purposes, anyway.

这篇关于JS Chrome top.document的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 01:06