第八章 BOM
8.1window对象
193
var age=20;
function sayAge(){
console.log(this.age);
}
console.log(window.age);
sayAge();
window.sayAge();
194
var age=20;
window.color="red";
delete window.age;
delete window.color;
console.log(window.age);
console.log(window.color);
var newValue=oldValue;
var newValue=window.oldValue;
var leftPos=(typeof window.screenLeft=="number") ? window.screenLeft : window.screenX;
var topPos=(typeof window.screenTop=="number") ? window.screenTop : window.screenY;
var pageWidth=window.innerWidth;
var pageHeight=window.innerHeight;
if(typeof pageWidth!="number"){
if(document.compatMode == "CSS1Compat" ){
pageWidth=document.documentElement.clientWidth;
pageHeight=document.documentElement.clientHeight;
}else{
pageWidth=document.body.clientWidth;
pageHeight=document.body.clientHeight;
}
}
var jh=window.open("http://www.google.cn","_blank","height=400,widht=200,top=200,left=200,resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no");
jh.resizeTo(40,40);
jh.moveTo(50,50);
jh.close();
console.log(jh.closed);
console.log(jh.opener == window);
var blocked=false;
try{
var jh=window.open("http://www.google.cn","_blank");
if(jh==null){
blocked=true;
}
}catch(ex){
blocked=true;
}
if(blocked==true){
alert("the popup was blocked!");
}
var timeoutId=setTimeout(function(){
console.log("hello");
},10
);
clearTimeout(timeoutId);
interval
clearInterval
var num=0;
var max=10;
setTimeout(incrementNumber,500);
function incrementNumber(){
console.log(num++);
if(num<max){
setTimeout(incrementNumber,500);
}else{
alert("done");
}
}
alert("are you ok");
confirm("are you ok");
prompt("are you ok","i am ok");
8.2 location对象
location.host