JavaScript Series 4: browser objects and javascript Series

Source: Internet
Author: User

JavaScript Series 4: browser objects and javascript Series

1. window object
The Window object is the core of BOM, and the window object refers to the current browser Window.
Alert () displays a warning box with a message and a confirmation button
Prompt () displays a dialog box prompting users to enter
Confirm () displays a dialog box with a message, a confirmation button, and a Cancel button.
Open () open a new browser window or find a named window
Close () close the browser window
Print () print the content of the current window
Focus () gives the keyboard focus to a window
Blur () removes the keyboard window from the top-level window
MoveBy () moves the specified pixel relative to the current coordinate of the window.
MoveTo () can be moved to a specified coordinate relative to the upper left corner of the window.
ResizeBy () adjusts the window size according to the specified Pixel
ResizeTo () adjusts the window size to the specified width and height.
ScrollBy () is used to scroll the content based on the specified pixel value.
ScrollTo () Scrolls the content to the specified Coordinate
SetInterval () executes the code at a specified time
SetTimeout () executes the code after the specified Delay Time
ClearInterval () cancels setInterval () settings
ClearTimeout () cancels setTimeout () settings

2. JavaScript Timer
In JavaScript, we can execute the code after the set interval, instead of immediately executing the code after the function is called.

Timer type:
One-time Timer: triggered only once after the specified Delay Time
Interval trigger Timer: Each timer is triggered at a certain interval.
Timer method:
SetTimeout () specifies the delay time to run the code
ClearTimeout () cancels setTimeout () settings
SetInterval () executes the code at a specified time
ClearInterval () Cancel setInterval () settings

3. Timer setInterval ()
During execution, the code is executed at specified intervals after the page is loaded.
Syntax:
SetInterval (Code, interaction time );
Parameter description:
1. Code: the function to be called or the code string to be executed.
2. interaction time: the time interval between periodical execution or calling expressions, in milliseconds (1 s = 1000 ms ).
Return Value:
A value that can be passed to clearInterval () to cancel the periodical execution of the Code.

4. Cancel the timer clearInterval ()
The clearInterval () method can cancel the interaction time set by setInterval ().
Syntax:
ClearInterval (id_of_setInterval)
Parameter description:
Id_of_setInterval: ID value returned by setInterval ()

5. Timer setTimeout ()
SetTimeout () timer. After the timer is loaded and delayed for a specified time, the expression is executed once and only once.
Syntax:
SetTimeout (Code, latency );
Parameter description:
1. The function to be called or the code string to be executed
2. latency: the waiting time before code execution, in milliseconds

6. Cancel the timer clearTimeout ()
SetTimeout () and clearTimeout () are used together to stop the timer.
Syntax:
ClearTimeout (id_of_setTimeout)
Parameter description:
Id_of_setTimeout: ID value returned by setTimeout (). This value indicates the code block to be canceled.

7. History Object
The history Object records the pages (URLs) that the user has browsed, and allows the browser to move forward and backward in similar navigation.
Note:
Records the window from the moment it is opened. Each browser window, each tab, and even each frame have their own history object associated with a specific window object.
Syntax:
Window. history. [attribute | method]
Note:
Window can be omitted
History Object Attributes
Length returns the number of URLs in the browser history list.
History Object Method
Back () loads the previous URL in the history List
Forward () loads the next URL in the history List
Go () loads a specific page in the history list

8. Return to the previous page
The back () method to load the previous URL in the history list.
Syntax:
Windows. history. back ()
Note:
It is equivalent to clicking the browser's backward button.
Back () is equivalent to go (-1)

9. Return to the next page
Forward () method to load the next URL in the history list.
If you want to return to the page that you browsed before regressing, you can use the forward () method. The Code is as follows:
Window. history. forward ();
Note: Click forward.
Forward () is equivalent to go (1)

10. Return to other pages in the browsing history
The go () method loads a specific page in the history list based on the current page.
Syntax:
Window. history. go (number );
Parameters:
1 first, go (1) is equivalent to forward ()
0 current page
-After 1, go (-1) is equivalent to back ()
The relative location of the URL to be accessed by other numeric values in the History URL list

11. Location object
Location is used to obtain or set the URL of the form, and can be used to parse the URL
Syntax:
Location. [attribute] [Method]
Location Object Property
Href: http://www.imooc.com: 8080/list. php? Courseid = 8 & chapterid = 86 # mediaid118
Set or return the complete URL
Protocol: http
Sets or returns the current Protocol
Host: www.imooc.com: 8080
Set or return the host name and the port number of the current URL
Hostname: www.imooc.com
Sets or returns the Host Name of the current URL.
Port: 8080
Set or return the port number of the current URL
Pathname: list. php
Set or return the path of the current URL
Search: courseid = 8 & chapterid = 86
Set or return slave? Start URL (query part)
Hash: mediaid118
Set or return the URL (Anchor) starting from)
Location object method:
Assign () loads new documents
Reload () reload the current document
Replace () replaces the current document with a new document

12. Navigator object
The Navigator object contains information about the browser, which is usually used to monitor the version of the browser and the operating system.
Object Property:
String Representation of the appCodeName browser code name
AppName: returns the browser name.
AppVersion: returns the platform and version information of the browser.
Platform returns to the operating system platform running the browser
UserAgent returns the user-agent header value sent by the client to the server.

13. userAgent
Returns the string representation of the user's proxy header (that is, a string including the browser version information)
Syntax:
Navigator. userAgent
Browser user_agent. For example, the compatibility mode of 360 uses IE, and the fast mode uses the chrom kernel.

Chrome: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) chrome/34.0.1847.116 Safari/537.36
FireFox: Mozilla/5.0 (WindowsNT6.1; WOW64; rv: 24.0) Gecko/20100101 fireFox/24.0
IE8: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; NET CLR2.0.50727; NET CLR3.5.30729;. NET CLR3.0.30729;. NET4.0C)
If (u_agent.indexOf ("Firefox")>-1 ){
B _name = "Firefox ";}
The indexOf () method returns the position of the first occurrence of a specified string value. If this string is not found,-1 is returned. If yes, the position of the string is returned.

14. screen Object
The screen object is used to obtain the user's screen information.
Syntax:
Windows. screen. Properties
The screen height that can be used by the availHeight window, in pixels.
The screen width that can be used by the availWidth window, in pixels.
ColorDepth the number of digits in the color represented by the user's browser, usually 32 bits (the number of bits per pixel)
PixelDepth: the number of digits in the color represented by the user's browser. Generally, 32-bit (number of digits per pixel) IE does not support
Height the screen height, in pixels.
Width: the screen width, in pixels.

15. Screen Resolution height and width
The window. screen Object contains information about the user's screen.
1. screen. height return the screen resolution height
2. screen. width: return the screen resolution width.
Note:
1. The unit is pixel.
2. The window. screen object can be written without the window prefix.

16. Available screen height and width
1. The screen. availWidth attribute returns the width of the visitor's screen, in pixels, minus the interface features, such as the taskbar.
2. The screen. availHeight attribute returns the height of the visitor's screen, in pixels, minus the interface features, such as the taskbar.
Note:
The default height of the taskbar varies depending on the system, and the taskbar can be located at any position on the screen, so the available width and height may be different.

Var num = document. getElementById ("second"). innerHTML;
// Obtain the element that shows the number of seconds. Use the timer to change the number of seconds.

Function count ()
{
Num --;
Document. getElementById ("second"). innerHTML = num;
If (num = 0)
{
Location. assign ("www.imooc.com ");
}
}
Set interval ("count ()", 1000 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.