js window

获取屏幕宽度

var w=window.innerWidth

|| document.documentElement.clientWidth

|| document.body.clientWidth;

var h=window.innerHeight

|| document.documentElement.clientHeight

|| document.body.clientHeight;


window.open() - 打开新窗口

window.close() - 关闭当前窗口

window.moveTo() - 移动当前窗口

window.resizeTo() - 调整当前窗口的尺寸



获取屏幕可用宽度,高度

document.write("可用宽度:" + screen.availWidth);

document.write("可用高度:" + screen.availHeight);


location:

显示网页

function newDoc()

{

window.location.assign("http://www.w3school.com.cn")

}


Window History

history.back() - 与在浏览器点击后退按钮相同

history.forward() - 与在浏览器中点击按钮向前相同


Window Navigator

txt = "Browser CodeName: " + navigator.appCodeName + "

";txt+= "Browser Name: " + navigator.appName + "

";txt+= "Browser Version: " + navigator.appVersion + "

";txt+= "Cookies Enabled: " + navigator.cookieEnabled + "

";txt+= "Platform: " + navigator.platform + "";

txt+= "User-agent header: " + navigator.userAgent + "

";txt+= "User-agent language: " + navigator.systemLanguage + "";


alert("提示框");

confirm("是否");

prompt("文本","默认值");


5秒后弹出提示框

var t=setTimeout("alert('5 seconds!')",5000)



function demo(e){

var boo = window.confirm("确定访问么吗?");

if(e && e.preventDefault){

// 说明非IE浏览器

if(!boo){

// 取消

e.preventDefault();

}else{

// 确定

}

}else{

if(!boo){

// IE

e.returnValue = false;

}

}

}

function demo2(e){ // 只弹button 不弹div

// 区分浏览器

if(e && e.stopPropagation){

// 非ie浏览器

e.stopPropagation();

alert("button");

}else{

// ie浏览器

alert("IE");

e.cancelBubble = true;

}

}

按钮

你可能感兴趣的:(js window)