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 浏览器版本号