Javascript中封裝window.open解決不兼容問題
來源:易賢網(wǎng) 閱讀:1860 次 日期:2014-09-29 11:19:09
溫馨提示:易賢網(wǎng)小編為您整理了“Javascript中封裝window.open解決不兼容問題”,方便廣大網(wǎng)友查閱!

對window.open進行封裝, 使其更好用, 且更兼容, 很多人說window.open不兼容,其實不是, 因為不能直接執(zhí)行, 必須通過用戶手動觸發(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 }); }

更多信息請查看IT技術(shù)專欄

更多信息請查看腳本欄目
易賢網(wǎng)手機網(wǎng)站地址:Javascript中封裝window.open解決不兼容問題
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)