《JavaScript高级程序设计2》学习笔记——BOM

View Code
   
   
var leftPos = ( typeof window.screenLeft == " number " ) ? window.screenLeft : window.screenX;
var topPos = ( typeof window.screenTop == " number " ) ? window.screenTop : window.screenY;
// alert(leftPos + "," + topPos);
//
alert(top.screenX);
window.moveTo( 0 , 0 );
window.moveBy(
100 , 100 );


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;
}
}
// document.write("pageWidth : " + pageWidth + " , " + "pageHeight : " + pageHeight);
window.resizeTo( 500 , 500 ); // 调整到500 X 500
window.resizeBy( 100 , 50 ); // 调整到600 X 550


window.open(
" http://ce.sysu.edu.cn/ " , " _blank " );
var ceWin = window.open( " http://ce.sysu.edu.cn/ " , " _blank " , " height:400,width:400,top:10,left:10,resizable=yes,status=yes " );
alert(ceWin.opener
== window);
if (ceWin == null ) {
alert(
" The popup was blocked. " );
}
// 检测window.onen()方法打开的窗口是否被屏蔽了
var blocked = false ;
try {
var ceWin = window.open( " http://ce.sysu.edu.cn/ " , " _blank " , " height:400,width:400,top:10,left:10,resizable=yes,status=yes " );
if (ceWin == null ) {
blocked
= true ;
}
}
catch (ex) {
blocked
= true ;
}
if (blocked) {
alert(
" The popup was blocked. " );
}

setTimeout(
function () {
alert(
" Hello! " );
},
1000 );
var timeoutId = setTimeout( function () {
alert(
" Hello! " );
},
2000 );
clearTimeout(timeoutId);
setInterval(
function () {
alert(
" Hello! " );
},
1000 );
// 间歇调用
var num = 0 ;
var max = 5 ;
var intervalId = null ;
function incrementNumber() {
num
++ ;
if (num == max) {
clearInterval(intervalId);
alert(
" Done! " );
}
}
intervalId
= setInterval(incrementNumber, 500 );
// 超时调用
var num = 0
var max = 5 ;
function incrementNumber() {
num
++ ;
if (num < max) {
setTimeout(incrementNumber,
500 );
}
else {
alert(
" Done! " );
}
}
setTimeout(incrementNumber,
500 );

function getQueryStringArgs() {
var qs = (location.search.length > 0 ) ? location.search.subString( 1 ) : "" ;
var args = {};
var value = null , name = null , item = null ;
var items = qs.split( " & " );
for ( var i = 0 , len = items.length; i < len; i ++ ) {
item
= items[i].split( " = " );
name
= decodeURIComponent(item[ 0 ]);
value
= decodeURIComponent(item[ 1 ]);
args[name]
= value;
}
return args;
}

alert(navigator.appCodeName);
// Mozilla
//
alert(navigator.appName);
alert(navigator.cookieEnabled); // true
alert(navigator.cpuClass); // x86
alert(navigator.language); // zh-cn
alert(navigator.onLine); // false
alert(navigator.platform); // Win32
alert(navigator.plugins); //
alert(navigator.product); //
alert(navigator.systemLanguage); // zh-cn
alert(navigator.userLanguage); // zh-cn
function hasPlugin(name) { // 非IE中检测插件
name = name.toLowerCase();
for ( var i = 0 ; i < navigator.plugins.length; i ++ ) {
if (navigator.plugins[i].name.toLowerCase().indexOf(name) > - 1 ) {
return true ;
}
}
return false ;
}
alert(hasPlugin(
" Flash " ));
alert(hasPlugin(
" Java " )); */
function hasIEPlugin(name) {
try {
new ActiveXObject(name);
return true ;
}
catch (ex) {
return false ;
}
}
alert(hasIEPlugin(
" ShockwaveFlash.ShockwaveFlash " ));

你可能感兴趣的:(JavaScript)