對(duì)window.open進(jìn)行封裝, 使其更好用, 且更兼容, 很多人說window.open不兼容,其實(shí)不是, 因?yàn)椴荒苤苯訄?zhí)行, 必須通過用戶手動(dòng)觸發(fā)才行;看代碼:
代碼如下
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("http://www.daermay.com/ ?rel=xuexb");}//demo 2:固定寬 并居中document.body.onclick = function(){openWindow("http://m.survivalescaperooms.com/ ?rel=xuexb",{width:888});}新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注