前端开发

 首页 > 前端开发 > jquery教程 > Javascript中封装window.open解决不兼容问题_jquery_自学

Javascript中封装window.open解决不兼容问题_jquery_自学

分享到:
【字体:
导读:
          window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行,下面有个实例,大家可以看看...

对window.open进行封装, 使其更好用, 且更兼容, 很多人说window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行;看代码:

代码如下

var openWindow = function(url, options) {
var str = "";
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 (var i in options) {
str += ',' + i + '=' + options[i];
}
str = str.substr(1);
};
window.open(url, 'connect_window_'+ (+new Date), str);//参数1为url,参数2为了能可以重复弹出
str = null;
};


//demo 1:新窗口打开我的led投光灯电源网站
document.body.onclick = function(){
openWindow("http://www.daermay.com/ ?rel=xuexb");
}

//demo 2:固定宽 并居中
document.body.onclick = function(){
openWindow("http://www.jb51.net/ ?rel=xuexb",{
width:888
});
}
分享到:
jQuery固定浮动侧边栏实现思路及代码_jqu...
这个功能现在应用的非常普遍,如果页面比较高,当滚动条拖到页面的下面的时候,侧边栏会出现一个固定跟随浏览器的DIV框,现思路是这样的:首先获取需要跟随的DIV距离页面顶部的距离,然后判断,当浏览器滚动的距离大于该DIV本身距离顶部距离的时候,则添加CSS属性fixed即可。 代码如下 HTML代码: header Sidebar...
jQuery获取iframe的document对象的方法_j...
获取iframe的document对象的目的就是进行dom的操作 $(function() { var result = $('#myframe').prop('contentWindow').document; console.log(result); }); 这样输出来的结果是:document对象
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……