JavaScript series four: Browser objects

Source: Internet
Author: User
Tags setinterval


1. Window object
The Window object is the core of the BOM, which refers to the current browser window.
Alert () Displays a warning box with a message and a confirmation button
Prompt () Displays a dialog box to prompt the user for input
Confirm () Displays a dialog box with a message and a confirmation button and a Cancel button
Open () Opens a new browser window or looks for a named window
Close () Closes the browser window
Print () Prints the contents of the current window
Focus () gives keyboard focus to a window
Blur () Move the keyboard window away from the top-level window
Moveby () moves it to the specified pixel relative to the current coordinates of the window
MoveTo () can be moved to a specified coordinate relative to the upper-left corner of the window
Resizeby () Resizes the window according to the specified pixel size
Resizeto () Adjusts the size of the window to the specified width and height
Scrollby () Scrolls content by the specified pixel value
ScrollTo () Scrolls the content to the specified coordinates
SetInterval () executes code for each specified time
SetTimeout () Executes the code after the established delay time
Clearinterval () Cancel settings for setinterval ()
Cleartimeout () Cancel settings for settimeout ()

2. JavaScript timer
In JavaScript, we can execute code after a set interval, not immediately after a function is called.

Timer Type:
One-time timer: Only fires once after a specified delay time
Interval Trigger timer: Fires once per certain interval.
Timer method:
SetTimeout () Specify delay time to execute code
Cleartimeout () Cancel settimeout () setting
SetInterval () executes code for each specified time
Clearinterval () Cancel setinterval () setting

3, Timer setinterval ()
Executes the code at the specified time after the page is loaded.
Grammar:
SetInterval (Code, interaction time);
Parameter description:
1. Code: The function to invoke or the code string to execute.
2. Interaction time: The time interval between periodic execution or invocation of an expression, in milliseconds (1s=1000ms).
return value:
A value that can be passed to clearinterval () to suppress periodic execution of "code."

4. Cancel Timer clearinterval ()
Clearinterval () method to cancel the interaction time set by SetInterval ()
Grammar:
Clearinterval (Id_of_setinterval)
Parameter description:
Id_of_setinterval: Return ID value by SetInterval ()

5, Timer settimeout ()
SetTimeout () timer, after loading and delaying a specified time, to execute an expression once, only once
Grammar:
SetTimeout (code, delay time);
Parameter description:
1. The function to invoke or the code string to execute
2. Delay time: The amount of time to wait before executing the code, in milliseconds

6. Cancel Timer cleartimeout ()
SetTimeout () and cleartimeout () are used together to stop the timer.
Grammar:
Cleartimeout (Id_of_settimeout)
Parameter description:
Id_of_settimeout: The ID value returned by SetTimeout () that represents the deferred execution code block to be canceled.

7. History Object
The history object records the pages (URLs) that the user has browsed, and enables the browser to move forward and backward with similar navigation capabilities.
Attention:
Starting from the moment the window is opened, each browser window, every tab, and even each frame has its own history object associated with a particular window object.
Grammar:
Window.history. [Properties | method]
Attention:
Window can be omitted
History Object Properties
Length returns the number of URLs in the browser history list
History Object method
Back () load the previous URL in the history list
Forward () load the next URL in the history list
Go () Load a specific page in the history list

8. Go back to the previous browse page
Back () method to load the previous URL in the history list
Grammar:
Windows.history.back ()
Attention:
Equivalent to clicking the browser's rewind button
Back () equivalent to go (-1)

9. Return to the next browse page
Forward () method to load the next URL in the history list.
If you want to go back to the page you browsed before going backwards, you can use the forward () method, which is the following code:
Window.history.forward ();
Note: Equivalent click forward button.
Forward () equivalent to go (1)

10. Return to other pages in browsing history
The Go () method loads a specific page in the History list, depending on the page currently in place.
Grammar:
Window.history.go (number);
Parameters:
1 Previous, Go (1) equivalent forward ()
0 Current Page
-1 Next, Go (-1) equivalent back ()
Other values the relative position of the URL to access in the history's URL list

11. Location Object
Location is used to get or set the URL of the form and can be used to resolve URLs
Grammar:
Location. Properties Method
Location Object Properties
href:http://www.imooc.com:8080/list.php?courseid=8&chapterid=86#mediaid118
Sets or returns the full URL
Protocol:http
Sets or returns the current protocol
host:www.imooc.com:8080
Sets or returns the host name and port number of the current URL
Hostname:www.imooc.com
Sets or returns the host name of the current URL
port:8080
Sets or returns the port number of the current URL
pathname:list.php
Sets or returns the path portion of the current URL
Search:courseid=8&chapterid=86
Set or return from? URL to start (Query section)
hash:mediaid118
Sets or returns the URL (anchor) starting with #
Location Object method:
Assign () loading a new document
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 and is typically used to monitor the browser and operating system version
Object properties:
appCodeName a string representation of the browser code name
AppName returns the name of the browser
AppVersion returns the platform and version information of the browser
Platform returns the operating system platform running the browser
UserAgent returns the value of the user-agent header of the server sent by the client

13, UserAgent
Returns a string representation of the user-agent header (that is, a string that includes browser version information, etc.)
Grammar:
Navigator.useragent
Several browsing user_agent., like 360 compatibility mode with IE, speed mode with 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 in the string, and returns 1 if the string is not found, where the string is located.

14. Screen Object
The screen object is used to get the user's onscreen information.
Grammar:
Windows.screen. Properties
availheight window can use the screen height, unit px
Availwidth window can be used for screen width, unit px
ColorDepth the number of color bits represented by the user's browser, typically 32 bits (bits per pixel)
Pixeldepth: The number of color bits represented by the user's browser, usually 32 bits (bits per pixel) IE does not support
Height of a height screen, unit px
Width of screen, unit px

15, the screen resolution of the High and wide
The Window.screen object contains information about the user's screen.
1. Screen.height returns the high screen resolution
2. Screen.width returns the width of the screen resolution
Attention:
1. Units are measured in pixels.
2. The Window.screen object can be written without using the window prefix.

16, the screen can be high and width
1. The Screen.availwidth property returns the width of the visitor's screen, in pixels, minus interface features such as the taskbar.
2. The Screen.availheight property returns the height of the visitor's screen, in pixels, minus interface features such as the taskbar.
Attention:
The taskbar's default height is not the same on different systems, and the taskbar position can be anywhere on the screen, so it's possible that the width and height are not the same.

var Num=document.getelementbyid ("Second"). InnerHTML;
Gets the element that displays the number of seconds, using the timer to change the number of seconds.

function count ()
{
num--;
document.getElementById ("Second"). Innerhtml=num;
if (num==0)
{
Location.assign ("www.imooc.com");
}
}
SetInterval ("Count ()", 1000);

JavaScript series four: Browser objects

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.