[an error occurred while processing this directive]
Every Javascript program can refer to the following global objects:
name | description |
---|---|
document
|
current HTML page and its content |
history
|
list of pages the user has visited |
location
|
URL of the current HTML page |
navigator
|
info about the web browser you are using |
screen
|
info about the screen area occupied by the browser |
window
|
the browser window |
window
objectthe entire browser window; the top-level object in DOM hierarchy
window
objectdocument
,
history
,
location
,
name
alert
,
confirm
,
prompt
(popup boxes)
setInterval
,
setTimeout
clearInterval
,
clearTimeout
(timers)
open
,
close
(popping up new browser windows)
blur
,
focus
,
moveBy
,
moveTo
,
print
,
resizeBy
,
resizeTo
,
scrollBy
,
scrollTo
window.open
window.open("http://foo.com/bar.html", "My Foo Window", "width=900,height=600,scrollbars=1");
window.open
pops up a new browser windowdocument
objectthe current web page and the elements inside it
anchors
,
body
,
cookie
,
domain
,
forms
,
images
,
links
,
referrer
,
title
,
URL
getElementById
getElementsByName
,
getElementsByTagName
querySelector
,
querySelectorAll
close
,
open
,
write
,
writeln
location
objectthe URL of the current web page
host
,
hostname
,
href
,
pathname
,
port
,
protocol
,
search
assign
,
reload
,
replace
navigator
objectinformation about the web browser application
appName
,
appVersion
,
browserLanguage
,
cookieEnabled
,
platform
,
userAgent
navigator
object to see what browser is being used, and write browser-specific scripts and hacks:
if (navigator.appName === "Microsoft Internet Explorer") { ...
screen
objectinformation about the client's display screen
availHeight
,
availWidth
,
colorDepth
,
height
,
pixelDepth
,
width
history
objectthe list of sites the browser has visited in this window
length
back
,
forward
,
go
history
properties, for securitymethod | description |
---|---|
setTimeout(function, delayMS);
|
arranges to call given function after given delay in ms |
setInterval(function, delayMS);
|
arranges to call function repeatedly every delayMS ms |
clearTimeout(timerID); clearInterval(timerID);
|
stops the given timer |
setTimeout
and setInterval
return an ID representing the timer
clearTimeout
/Interval
later to stop the timer
setTimeout
example
<button id="clickme">Click me!</button> <span id="output"></span>
window.onload = function() {
document.getElementById("clickme").onclick = delayedMessage;
};
function delayedMessage() {
document.getElementById("output").innerHTML = "Wait for it...";
setTimeout(sayBooyah, 5000);
}
function sayBooyah() { // called when the timer goes off
document.getElementById("output").innerHTML = "BOOYAH!";
}
setInterval
example
var timer = null; // stores ID of interval timer function delayMsg2() { if (timer === null) { timer = setInterval(rudy, 1000); } else { clearInterval(timer); timer = null; } } function rudy() { // called each time the timer goes off document.getElementById("output").innerHTML += " Rudy!"; }
function delayedMultiply() {
// 6 and 7 are passed to multiply when timer goes off
setTimeout(multiply, 2000, 6, 7);
}
function multiply(a, b) {
alert(a * b);
}
setTimeout(multiply(6 * 7), 2000);
()
when passing the function
setTimeout(booyah(), 2000);setTimeout(booyah, 2000);setTimeout(multiply(num1 * num2), 2000);setTimeout(multiply, 2000, num1, num2);
()
?