Javascript learning: applications of JavaScript objects

Source: Internet
Author: User
Javascript scripting is an object-oriented Programming Language It also supports some simple object models supported by predefined objects.
Javascript objects are composed of two basic elements: attributes and methods.

Navigator object
The navigator object manages the basic information of the browser, such as the version number and operating system.
Appname display browser name
Appversion browser version
Platform client operating system
Online browser online?
Whether Java enabled () is enabled Navigator
< Html >
< Head >
< Title > Navigator object </ Title >
</ Head >
< Body >
Browser name:
< Script > Document. Write (navigator. appname) </ Script > < BR >
Browser version:
< Script > Document. Write (navigator. appversion) </ Script > < BR >
Operating System:
< Script > Document. Write (navigator. Platform) </ Script > < BR >
Online status:
< Script > Document. Write (navigator. Online) </ Script > < BR >
Java enabled or not:
< Script > Document. Write (navigator. javaenabled ()) </ Script > < BR >
</ Body >
</ Html >

Location object:
The location object is a static object built in the browser. It displays the address opened by a window object. when using location objects, you need to consider permissions. Different protocols or hosts cannot reference each other's location objects.
Hostname: return address Host Name
Port return address port number
Host returns the host name and port number. < Html >
< Head >
< Title > Location object </ Title >
</ Head >
< Body >
< Script Language = "JavaScript" >
Document. Write ( " Address Host Name: " );
Document. Write (location. hostname );
</ Script >
</ Body >
</ Html >

Window object:
A window object is an object with a high priority. A Window object contains rich attributes, methods, and other time-driven, Program You can perform simple operations on these simple attributes and methods to control the Browser display window.
Properties of the window object:
Self current window
Main parent window
Top Window
Status browser Status Bar
Window object method:
Open () Open
Close () Close
Alert () message box
Confirm () confirmation box
Prompt () Prompt box Window
< Html >
< Head >
< Title > Window object </ Title >
</ Head >
< Body >
The Baidu homepage (www.baidu.com) is displayed)
< Script Language = "JavaScript" >
Window. Open ( " Http://www.baidu.com " , " Newwindow " , " Height = 200, width = 300, Top = 50, Left = 50 " )
</ Script >
</ Body >
</ Html >

Document Object:
Javascript input and output must be completed through an object. document is one of the output objects. The most important method of the Document Object is write () < Html >
< Head >
< Title > Document Object </ Title >
</ Head >
< Body >
< Script Language = "JavaScript" >
Document. Write ( " <Font color = Red> have you learned JavaScript today? </Font> " );
</ Script >
</ Body >
</ Html >

History Object:
In JavaScript scripting language, the History Object indicates the browsing history, which contains the web address of the web page browsed by the browser before.
Forward () is equivalent to the "Forward" button on the toolbar of the browser.
Back () is equivalent to the "back" button on the toolbar of the browser.
Go () is equivalent to the "go to" button on the toolbar of the browser. History
< Html >
< Head >
< Title > History Object </ Title >
</ Head >
< Body >
< Script Language = "JavaScript" >
Document. Write ( " <Font color = Red> have you learned JavaScript today? </Font> " );
</ Script >
< Form >
< Input Name = "Forward" Type = "Button" Onclick = "History. Go (1 )" Value = "Forward" >
< Input Name = "Back" Type = "Button" Onclick = "History. Go (-1 )" Value = "Back" >
< Input Name = "Go" Type = "Button" Onclick = "History. Go (2 )" Value = "Go" >
</ Form >
</ Body >
</ Html >

Built-in objects and methods:
The properties and methods of built-in objects provided by JavaScript are the same as those of other object-oriented programming languages:
Object Name. attribute name
Object Name. Method Name (parameter)
Date object: getdate, getday, gethour, getmouth, getseconds, setday, sethour, setmouth, setseconds
String object: indexof (), charat (), tolowercase (), toupcase (), substring ()
Math objects: ABS (), ACOs (), atan (), max (), min (), SPRT ()
Array object: defines an array

You can also customize objects as needed.

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.