自我文档这个顶级窗口 [英] Self Document This Top Window

查看:71
本文介绍了自我文档这个顶级窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一些随机代码,如下所示:

Let's say I have some random code like below:

<script>

    this.fn = (function() {
        var element = document.createElement("div");
        element.innerHTML = Object.keys(self) + 
            "<br />" + Object.keys(window) +
            "<br />" + Object.keys(top);    

        self["document"].body.appendChild(element);
        return arguments.callee;
    })();

</script>

不仅要使用上面的代码,还有什么区别:

自我文件热门窗口


每个最佳用例是什么?

Not only having to do with the above code, what's the difference between:
Self, Document, This, Top, Window?

What's a best use case for each?

推荐答案

self & 窗口 :它们都引用脚本所在和运行的当前窗口(或框架)。有关详细信息和示例,请参见此处

document :引用DOM容器,使您可以访问标题和正文内容。有关详细信息和示例,请参见此处

:引用执行代码的JavaScript对象。直接在< script> 标签内编写的JavaScript代码和函数有引用窗口。如果对象的函数需要在同一对象中调用方法,请使用 this.method_name();

this : References the JavaScript object under which the code is executed. JavaScript code and functions written directly inside <script> tags have this refer to window. If an object's function needs to call a method in the same object, use this.method_name();.

top :引用框架层次结构中最顶层的窗口对象。如果您使用框架并想要从子框架内操作整个框架集窗口,请使用 top ,例如 top.close(); 关闭包含所有帧的当前窗口。

top : References the top-most window object in a frame hierarchy. If you use frames and want to manipulate the whole frameset window from inside a sub-frame, use top, e.g. top.close(); to close the current window containing all the frames.

这篇关于自我文档这个顶级窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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