Window
window對(duì)象表示瀏覽器中打開的窗口.
- confirm 確認(rèn)彈窗
funcation testConfirm() {
var a = window.confirm('是否退出');
if(a){
window.close();
}else{
window.alert('hhhh');
}
}
- prompt
prompt(text,defaultText)
text 表示提示內(nèi)容
defaultText表示默認(rèn)顯示內(nèi)容
function testPrompt() {
var a = window.prompt('請(qǐng)輸入密碼','123');
alert(a);
}
- move&&resize 改變窗口的位置和大小
function testMoveBy() {
window.moveBy(50,50);
}
function testMoveTo() {
window.moveTo(250,250);
}
function testResizeBy() {
window.resizeBy(50,50)
}
function testResizeBy() {
window.resizeTo(350,350);
}
經(jīng)測(cè)試chrome瀏覽器不支持move和resize.
scrollBy()和scrollTo()的用法類似move和resize.
- open
window.open(URL,name,features,replace)
URL : 如果不是空的就打開相應(yīng)URL的窗口 反之則打開一個(gè)空白窗口
name : 新窗口的名稱, 若該參數(shù)指定了一個(gè)已經(jīng)打開的窗口,則open方法不會(huì)再打開新窗口,只是指定對(duì)窗口的引用,這樣features參數(shù)將會(huì)被忽略.
features :
replace : true-url替換瀏覽歷史中的當(dāng)前條目,false-url在瀏覽歷史中創(chuàng)建新的條目.
- setInterval&&clearInterval
setIntval方法可以按照指定的周期(ms)來調(diào)用指定的函數(shù)或者表達(dá)式.指導(dǎo)clearInterval方法被調(diào)用或者window被close.
clearInterval方法可取消由setInterval創(chuàng)建的timeout,它的參數(shù)必須是由setInterval創(chuàng)建的ID;
<!DOCTYPE html>
<html>
<head>
<title>JOE</title>
<script type="text/javascript">
var i = window.setInterval('time()', 50);
function time() {
var t = new Date();
document.getElementById('time1').innerHTML = t;
}
</script>
</head>
<body>
<p id='time1'></p>
<input type="button" value="stop" onclick="javascript:window.clearInterval(i)" />
</body>
</html>
Navigator
navigator包含瀏覽器的信息.
with(navigator){
document.write('<p>appCodeName:'+appCodeName+'</p><br/>');
document.write('<p>appName:'+appName+'</p><br/>');
document.write('<p>appVersion:'+appVersion+'</p><br/>');
document.write('<p>cookieEnabled:'+cookieEnabled+'</p><br/>');
document.write('<p>onLine:'+onLine+'</p><br/>');
document.write('<p>platform:'+platform+'</p><br/>');
document.write('<p>userAgent:'+userAgent+'</p><br/>');
}
Screen
screen對(duì)象包含客戶端顯示的屏幕信息.
History
back()
加載history列表中的前一個(gè)urlforward()
加載history列表中的下一個(gè)urlgo()
加載history列表中的具體的那一個(gè)url, 傳-1代表前一個(gè), 1 代表下一個(gè), 0是當(dāng)前,一次類推.
Location
location對(duì)象包含有關(guān)當(dāng)前url的信息.
with(location){
document.write('<p>hash:'+hash+'</p><br/>');
document.write('<p>host:'+host+'</p><br/>');
document.write('<p>hostname:'+hostname+'</p><br/>');
document.write('<p>href:'+href+'</p><br/>');
document.write('<p>pathname:'+pathname+'</p><br/>');
document.write('<p>port:'+port+'</p><br/>');
document.write('<p>protocol:'+protlcol+'</p><br/>');
document.write('<p>search:'+search+'</p><br/>');
}