JavaScript Functions and Window objects

Source: Internet
Author: User

First, what is a function

Function: Similar to a method in Java, it is easier to use a block of code that accomplishes a specific task: no definition belongs to a class, directly using

Second, common system functions

parseint ("string") converts a string to an integer number

Example: parseint ("86") converts the string "86" to an integer value of parsefloat ("string")

Converts a string to a floating-point number such as: parsefloat ("34.45") converts the string "34.45" to a floating-point value 34.45 IsNaN ()

Used to check whether its parameters are non-numeric

Three, custom function creation function:

1. No parameter function

Function name () {

JavaScript code;


2. Function with parameters

Function name (parameter 1, parameter 2, ...) {

JavaScript code;


3. Call the function function to invoke the general and form element events together with the call format:

Event name = "function name ()";

Four. Common Properties for Window objects

1.screen (information about the client's screen and display performance)

2.history (information about URLs visited by customers, browsing history)

3.location (information about the current URL, jump-loaded page)

Five. Common Methods for Window objects

1. Prompt(displays a dialog box that prompts the user for input)

2. Alert(Displays a warning box with a hint message and a OK button)

3. Confirm(displays a dialog box with a hint, OK, and Cancel button)

4.Close (Closes the browser window)

5.Open (opens a new browser window to load the document specified by the given URL)

6.SetTimeout(call a function or evaluate an expression after a specified number of milliseconds)

7.setinterval(the function or expression is called in milliseconds, according to the specified period)

Vi. Open () method

1. Height,width (window document display area of the heights, widths. measured in pixels)

2. Left, Top(the x-coordinate and y-coordinate of the window. measured in pixels)

3.toolbar=yes | No | | 0 (whether or not to display the browser's toolbar.) Mo is yes. )

4.scrollbars=yes | No | | 0 (whether scroll bars are displayed.) Mo is yes. )

5.location=yes | No | | 0 (whether the address lot is displayed.) Mo is yes. )

6.status=yes | No | | 0 (whether to add the status bar.) Mo is yes. )

7.menubar=yes | No | | 0 (whether the menu bar is displayed or not.) Mo is yes. )

8.resizable=yes | No | | 0 (the window can be adjusted for size.) Mo is yes. )

9.titlebar=yes | No | | 0 (whether the title bar is displayed.) Mo is yes. )

10.fullscreen=yes | No | | (whether to use full-screen mode to display the browser.) Mo is No. A window in full-screen mode must be in theater mode at the same time. )

Vii. Common events for Window objects

1.onload(a page or an image to complete loading)

2.onmouseoveR (mouse over an element)

3.Onlick(the event handle that is called when the user clicks on an object)

4.ONKEYDOWM ( a keyboard key is pressed)

5.onchange(the content of the domain is changed)

Eight, anonymous call function

Function name () {

JavaScript code


Calling function: onclick= "function name ()"

Common anonymous notation on the Internet

Mode One: Event name =function () {...}

Mode two: (function () {

JavaScript code;


Directly run the function window.onload=function () {...}

<body onload= "event name ()" >

ix. Date Object (get time)

var Date object =new Date (parameter)

Parameter format: MM DD,YYYY,HH:MM:SS

Method of the Date object

Seconds and Minutes (0 to 59)

Hours (0 to +) Day (0 to 6 (Day of the week))

Date (1 to 31 (days in the month))

Months (0 to 11 (January to December))

<script language= "javascript" type= "Text/javascript" >

function Disptime () {

var today = new Date (); Get current time

var hh = today.gethours (); Get hours, minutes, seconds

var mm = Today.getminutes ();

var ss = Today.getseconds ();

document.getElementById ("Myclock"). innerhtml=hh+ ":" +mm+ ":" +SS;



Ten, the timing function

SetTimeout () Usage setTimeout ("function called", "after specified time")

SetInterval () method SetInterval ("function called", "specified time interval")

var mytime=settimeout ("Disptime ()", 1000);

var mytime=setinterval ("Disptime ()", 1000);

SetTimeout () only executes disptime () once, if you want to make multiple calls using the setinterval () person let Disptime () itself call SetTimeout () again

JavaScript Functions and Window objects

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.