Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does window mean in javascript

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what window means in javascript. I hope you will get something after reading this article. Let's discuss it together.

In javascript, window means "window" and is a built-in host object that represents a browser window, which is supported by all browsers. All JavaScript global objects, functions, and variables automatically become members of the window object.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

In javascript, window means "window" and is a built-in host object.

The window object is the core of all objects in BOM, which not only is the parent of all objects in BOM, but also contains some window control functions.

The host object is the object provided by the environment where the JS script is executed, and it is the object provided by the browser. All BOM and DOM are host objects.

Window object

All browsers support window objects. It represents the browser window.

All JavaScript global objects, functions, and variables automatically become members of the window object.

Global variables are properties of the window object.

The global function is the method of the window object.

Even the document of HTML DOM is one of the properties of the window object:

Window.document.getElementById ("header")

Same as this:

Document.getElementById ("header")

1. Global window object

Any global function or variable in JavaScript is an attribute of window.

Var name= "shaking the earth"; [xss_clean] (window.name)

2. Window and self object

The self object is exactly the same as the window object, and self is usually used to confirm that it is within the current form.

[xss_clean] (window = = self); / / must be equal, always equal [xss_clean] (window.Top = = window.self); / / determine whether the current frame is the main frame

Window, self and window.self are equivalent.

3. Sub-objects of window

The main main objects of window are as follows:

JavaScript document object

JavaScript frames object

JavaScript history object

JavaScript location object

JavaScript navigator object

JavaScript screen object

4. Window function index (valid for IE only)

Form control function:

JavaScript moveBy () function: move the form x pixels horizontally from the current position, move the form y pixels vertically, x is negative, move the form to the left, y is negative, and move the form up.

JavaScript moveTo () function: move the upper-left corner of the form to the (XMagi y) point relative to the upper-left corner of the screen, and move the form out of the visual area of the screen when a negative number is used as a parameter.

The JavaScript resizeBy () function adjusts the width by w pixels and the height by h pixels relative to the current size of the form. If the parameter is negative, the form is shrunk and the form is enlarged.

The JavaScript resizeTo () function adjusts the width of the form to w pixels and the height to h pixels.

/ / equivalent to setting the absolute position

Create a new form function:

JavaScript open () function: opens (pops up) a new form

JavaScript close () function: close the form

JavaScript opener property: cross-form communication can be achieved through opener, but make sure that it is under the same domain name and that one form contains the opener of another form.

Window.open (url, name, features, replace)

Open function argument description:

Url-the URL to load the form

Name-the name of the new form (or the value of the HTML target property, target)

Features-A string that represents the properties of a form, each separated by a comma

Replace-A Boolean value indicating whether the newly loaded page replaces the currently loaded page. This parameter is usually not specified.

Example of open method:

A pop-up window appears when the connection browser reads the page when the new window is opened; method 2:

Self.close (); combined with setTimeout (), you can achieve the effect that the open window closes regularly.

Dialog box function:

JavaScript alert () function: pop-up message dialog box (with an OK button)

JavaScript confirm () function: pop-up message dialog box (which contains an OK button and a Cancel button)

JavaScript prompt () function: pop-up message dialog box (which contains an OK button, a Cancel button, and a text input box)

Alert ()

No, I won't.

Confirm (str)

The confirm () message dialog is exclusive, that is, nothing else can be done until the user clicks the button in the dialog box.

If (confirm ("sure to jump big?") {alert ("decisive jump");} else {alert ("wretched transfer of money");}

The display is as follows:

Prompt (str1, str2)

A function takes two parameters

Str1-the text to be displayed in the message dialog box cannot be modified

Str2-- the contents of the text box, which can be modified

Var sResult=prompt ("Please enter your name below", "Earth-shaking cow"); if (sResultkilling cow) {alert (sResult + "has transcended the killing of God");} else {alert ("John Doe has surpassed the killing of God");}

The display is as follows:

Time waiting and interval function:

JavaScript setTimeout () function

JavaScript clearTimeout () function

JavaScript setInterval () function

JavaScript clearInterval () function

1. SetTimeout () and clearTimeout () call the function after the specified time

Syntax:

SetTimeout (fun,time); fun: function body or function name, time specifies the time in milliseconds.

ClearTimeout (id); cancels the code to be executed by the specified setTimeout function

SetTimeout (function () {[xss_clean] ("triggered after 3 seconds");}, 3000) / / output setTimeout (fun1, 5000) after 3 seconds; / / output function fun1 () {[xss_clean] ("function name triggers after 5 seconds");}

2. SetInterval (), clearInterval (value) repeatedly call the function after the interval between the specified events

Syntax:

SetInterval (fun1,time) fun: function body or function name, the time specified by time, in milliseconds. Will return a value, this value is used to count the number of the function, the first is 1, the second is 2, indicating the number of setInterval functions.

The value returned by the clearInterval (value) value:setInterval () function, based on which you can stop repeating setInterval ().

Var I = 0X var h = setInterval (function () {[xss_clean] ("output every 3 seconds"); if (I > = 3) {clearInterval (h); [xss_clean] ("stop output");}}, 3000)

Note that javascript is single-threaded, so this timing function is actually implemented by inserting the execution queue.

Such as the following code:

Function fn () {setTimeout (function () {alert ('can you see me?');}, 1000); while (true) {}}

Alert (); will never be executed because the thread has been occupied by a dead loop.

_ window.location child object

Parsing URL object location

The properties of the location object are: href,protocal,host,hostname,port,pathname,search,hash

[xss_clean] (location.href + "); / http://localhost:4889/javascriptTest.html [xss_clean] (location.protocol +"); / / http: [xss_clean] (location.host +"); / / localhost:4889 [xss_clean] (location.hostname +"); / / localhost [xss_clean] (location.port +") / / 4889 [xss_clean] (location.pathname + ""); / / javascriptTest.html [xss_clean] (location.search + "line wrap"); / / http://localhost:4889/javascriptTest.html?id=1&name= Zhang San if the path is like this, output? id=1&name=%E5%BC%A0%E4%B8%89 [xss_clean] (location.hash) / / http: / / localhost:4889/javascriptTest.html#kk= Hello? id=1&name= Zhang San if the path is like this, then output # kk= Hello? id=1&name= Zhang San

Load a new document

Location.reload () reloads the page

Location.replace () this window loads a new document

Location.assign () this window loads a new document

Location = "http://www.baidu.com" / / Jump to the specified URL

Location = "search.html" / / relative path jump

Location = "# top" / / Jump to the top of the page

Browsing history

The back () and forward () functions of the History () object are the same as the browser's "back" and "forward" functions.

History.go (- 2); back two historical records

Browser and screen information

Full name of navigator.appName Web browser

Detailed string of navigator.appVersion Web browser vendor and version

Most of the navigator.userAgent client information

The operating system on which the navagator.platform browser is running

[xss_clean] (navigator.userAgent + "); / / Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 [xss_clean] (navigator.appName +"); / / Netscape [xss_clean] (navigator.appVersion + "") / / 5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 [xss_clean] (navigator.platform); / / Win32

The relationship between windows

Parent = = self only the top-level window returns true

The parent and top properties allow the script to refer to the ancestor of its form, which is usually created by elements and can be used to get the top-level window.

5. Event event object

The two most useful actions: prevent events from bubbling. Sometimes return false; doesn't work, so this might work.

/ / IE:window.event.cancelBubble = true;// stop bubbling window.event.returnValue = default behavior of false;// blocking event / / Firefox:event.preventDefault (); / / cancel default behavior of event event.stopPropagation () / / stop the spread of the incident after reading this article, I believe you have a certain understanding of "what is the meaning of window in javascript". If you want to know more about it, please follow the industry information channel. Thank you for your reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report