开发者

JS Chrome top.document

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.


Have you tried

if (top.document == 'undefined')
{
   top.document = window.top.document || null;
}

Also ive just tested in my chrome browser and top.document returns the actual document so not sure, what version are you using !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜