Window selfProperty

Window 对象 参考手册Window Object

Definition and Usage

The self property returns a reference to the current window object. Using this property, you can ensure that when multiple windows are opened, functions or properties within the current window are correctly called without confusion.

The self property is read-only.

Syntax

window.self

Note:window, self, and window.self are equivalent.



Browser Support

Property
self Yes Yes Yes Yes Yes

Example

Example

When the "Check Window" button is clicked, check() is called and checks the state of the current window to determine whether it is in the top-level window:

function check(){ if (window.top!=window.self) { document.write("<p>This window is not the top-level window! Am I in a frame?</p>") } else{ document.write("<p>This window is the top-level window!</p>") } }

Try it Yourself »


Window 对象参考手册Window Object Other Extensions