Home > Web Front-end > JS Tutorial > Detailed explanation of the use of javascript self object (picture and text tutorial)

Detailed explanation of the use of javascript self object (picture and text tutorial)

亚连
Release: 2018-05-19 15:18:36
Original
2045 people have browsed it

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>
Copy after login

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)

parameter usage when the second parameter of javascript replace() is a function (detailed explanation for everyone)

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template