解決window.open被瀏覽器攔截,或手機上無反應的問題。
主要是window.open有時候會被當作廣告進行攔截,網(wǎng)上辦法有很多,大概看了一下。
延遲跳轉(zhuǎn) 模擬按鈕 模擬表單
今天主要發(fā)一下 簡單的模擬按鈕。
function openurl(url) { //創(chuàng)建A標簽 var a = document.createElement('a'); //給創(chuàng)建好的a標簽賦值 a.setAttribute('href', url); //設(shè)置css 隱藏屬性 a.setAttribute('style', 'display:none'); //設(shè)置 a標簽為新窗口打開 a.setAttribute('target', '_blank'); //將設(shè)置好的a標簽,添加到 body 內(nèi) document.body.appendChild(a); //模擬點擊 a.click(); //移除a標簽 a.parentNode.removeChild(a); }
轉(zhuǎn)載請注明出處 AE博客|墨淵 ? 解決window.open被瀏覽器攔截的問題
發(fā)表評論