This article mainly introduces relevant information on the detailed use of the javascript self object. Friends who need it can refer to it
The Javascript self object refers to the window itself. The object it returns is exactly the same as the window object, which is also true. Because of this, the common methods and functions of the window object can use self instead of window. This article introduces the usage methods and examples of the self object.
We know that when opening any web page, the browser will First create a window. This window is a window object, which is also the global environment object and global scope object that js runs on. self refers to the window itself, and the object it returns is exactly the same as the window object. Because of this, self can be used instead of window for common methods and functions of the window object. For example, a common way of writing is "self.close();", put it in the tag: "Close the window< /a>", click the "Close window" link, and the current page is closed.
javascript self object usage examples:
<html> <head> <script language="JavaScript" type = "text/javascript"> <!-- if (top==self) { var main_frame = "http://www.manongjc.com"; var cur_url = self.location.href; var setframes = main_frame + "?" + cur_url; location.href = setframes; } //--> </script> </head> <body> </body> </html>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Several ways to comment code in javascript (picture and text tutorial)
Detailed explanation and simplicity of JavaScript cookie Example application (graphic tutorial)
The above is the detailed content of Detailed explanation of the use of javascript self object (picture and text tutorial). For more information, please follow other related articles on the PHP Chinese website!