我需要知道文档元素是否是页面的根节点。例如:
<html> <-- ROOT Node
<head></head>
<body>
<iframe>
<html>...</html> <-- other document
</iframe>
<iframe>
<html>...</html> <-- other document
</iframe>
</body>
</html>
在 iframe 1 或 2 中执行的 Javascript 应该知道它们的文档节点是否为根节点。
希望我能帮到您。
top.document === window.document
就足够了,window.top
只是使用top
的一种较慢的方式。 - Martin Jespersentop
赋值,它要么会被忽略,要么会抛出一个错误。此外,window 只是一个指向该框架全局命名空间的伪对象,所以显式地调用它只是绕了一个大弯路,有点像观光而不是使用高速公路。 - Martin Jespersentop
设置为全局变量时才会出现问题。如果你在函数内使用var top
进行设置,它就可以正常工作。 - lonesomeday