windowphp
系統對話框:瀏覽器
alert 警告url
confirm 確認spa
prompt 輸入彈出firefox
print 打印代理
新建窗口:code
window.open()orm
urlci
目標窗口(_parnet,_blank)字符串
參數選項
大小位置
width,height,top,left
是否顯示欄目
resizable
location
menubar
status
toolbar
可控制原窗口
1
2
|
var
box = window.open(
'http://www.qwphp.com'
);
box.alert(
'hello qwphp'
);
|
window.close()
關閉窗口
窗口位置和大小:
窗口位置
窗口離屏幕的位置,最大化時爲0
支持狀況
IE支持screenLeft,screenTop,
firefox支持screenX,screenY,
其餘都支持
兼容方案
1
2
|
var
leftX = (
typeof
screenLeft ==
'number'
) ? screenLeft : screenX;
var
topY = (
typeof
screenTop ==
'number'
) ? screenTop : screenY;
|
頁面可視大小
主流瀏覽器
innerWidth,innerHeight
IE瀏覽器
document.documentElement.clientWidth
IE6非標準模式
document.body.clientWidth;
兼容方案
1
2
3
4
5
6
7
8
9
10
11
|
function
getInnerWidth() {
var
width = window.innerWidth;
//這裏要加window,由於IE 會無效
if
(
typeof
width !=
'number'
) {
//若是是IE,就使用document
if
(document.compatMode ==
'CSS1Compat'
) {
width = document.documentElement.clientWidth;
}
else
{
width = document.body.clientWidth;
//非標準模式使用body
}
}
return
width;
}
|
1
2
3
4
5
6
7
8
9
10
11
|
function
getInnerHeight() {
var
height = window.innerHeight;
//這裏要加window,由於IE 會無效
if
(
typeof
height !=
'number'
) {
//若是是IE,就使用document
if
(document.compatMode ==
'CSS1Compat'
) {
height = document.documentElement.clientHeight;
}
else
{
height = document.body.clientHeight;
//非標準模式使用body
}
}
return
height;
}
|
間歇調用和超時調用:
按毫秒不停的執行代碼
setInterVal,clearInterval
指定毫秒後執行一次代碼
setTimeout,clearTimeout
location
屬性:
主機相關
host 主機名+端口
hostname 主機名
port 端口名
protocol 協議部分
後段字符串
pathname 路徑和文件名
search 查詢字符串
hash 錨點部分
href 整個URL
方法:
assign()
跳轉到指定頁面
reload()
重載url
replace()
替換url
可避免跳轉前歷史
獲取參數方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
function
getArgs() {
var
args = [];
//去除?號
var
qs = location.search.length > 0 ? location.search.substring(1) :
''
;
var
items = qs.split(
'&'
);
var
item =
null
, name =
null
, value =
null
;
for
(
var
i = 0; i < items.length; i++) {
item = items[i].split(
'='
);
name = item[0];
value = item[1];
args[name] = value;
}
return
args;
}
|
history
屬性:
length 歷史記錄數
方法:
back()
後退
forward()
前進
go(num)
跳轉指定頁
navigator
包含有關瀏覽器的信息:
userAgent
瀏覽器的用戶代理字符串
瀏覽器嗅探器:
browserdetect.js
BrowserDetect.browser 瀏覽器名稱
BrowserDetect.version 瀏覽器版本號