對(duì)window.open進(jìn)行封裝, 使其更好用, 且更兼容, 很多人說window.open不兼容,其實(shí)不是, 因?yàn)椴荒苤苯訄?zhí)行, 必須通過用戶手動(dòng)觸發(fā)才行;看代碼:
代碼如下:
?1234567891011121314151617181920212223242526272829 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); //默認(rèn)為居中 options.top = options.top || ((screen.height - options.height) / 2); //默認(rèn)為居中 for (var i in options) { str += ',' + i + '=' + options[i]; } str = str.substr(1); }; window.open(url, 'connect_window_'+ (+new Date), str);//參數(shù)1為url,參數(shù)2為了能可以重復(fù)彈出 str = null; }; //demo 1:新窗口打開我的led投光燈電源網(wǎng)站 document.body.onclick = function(){ openWindow(" ?rel=xuexb"); } //demo 2:固定寬 并居中 document.body.onclick = function(){ openWindow?rel=xuexb",{ width:888 }); }
更多信息請(qǐng)查看IT技術(shù)專欄