window.open在新窗口打开页面时被浏览器屏蔽的解决方法

使用 window.open() 方法打开新窗口会被浏览器拦截,可以绕开这个拦截机制,利用异步调用并使用变量后赋值url的方法,代码如下:

$.ajax({
    
    
	url:'your url',
	type: 'get',
	success: (data, status, xhr) => {
    
    
		// 新建变量,实例化window.open,然后再赋值url
		const _window = window.open()
		_window.location.href = 'your url'
	}
})

猜你喜欢

转载自blog.csdn.net/xjtarzan/article/details/123642572
今日推荐