Javascript中封装window.open解决不兼容问题
对window.open进行封装,使其更好用,且更兼容,很多人说window.open不兼容,其实不是,因为不能直接执行,必须通过用户手动触发才行;看代码:
代码如下
varopenWindow=function(url,options){
varstr="";
if(options){
options.height=options.height||420;
options.width=options.width||550;
options.left=options.left||((screen.width-options.width)/2);//默认为居中
options.top=options.top||((screen.height-options.height)/2);//默认为居中
for(variinoptions){
str+=','+i+'='+options[i];
}
str=str.substr(1);
};
window.open(url,'connect_window_'+(+newDate),str);//参数1为url,参数2为了能可以重复弹出
str=null;
};
//demo1:新窗口打开我的led投光灯电源网站
document.body.onclick=function(){
openWindow("http://www.daermay.com/?rel=xuexb");
}
//demo2:固定宽并居中
document.body.onclick=function(){
openWindow("https://www.nhooo.com/?rel=xuexb",{
width:888
});
}热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下