回调函数中window.open()被拦截
生活随笔
收集整理的這篇文章主要介紹了
回调函数中window.open()被拦截
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在回調函數中window.open默認是會被攔截的,因為瀏覽器判斷它不是用戶自己打開的,存在安全風險,所以可以偽造一個用戶點擊事件來避開,代碼如下:
function newWindow(url, id) { var a = document.createElement('a'); a.setAttribute('href', url); a.setAttribute('target', '_blank');a.setAttribute('id', id); if(!document.getElementById(id)) { document.body.appendChild(a);} a.click(); } 使用時直接將鏈接傳入url就行,id可傳可不傳。總結
以上是生活随笔為你收集整理的回调函数中window.open()被拦截的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AI自动标注神器!支持多通道、大尺幅数据
- 下一篇: Windows平台RTSP播放器/RTM