Bootstrap

ios中safari浏览器中window.open()无效的问题

除了sadari以外的浏览器,点击按钮后都会成功开启新页面。而在safari中认为window.open()是一种弹窗,而safari浏览器阻拦弹出式视窗。我这里是在uniapp中处理的方式,其他可自行调整。

解决办法:window.open()进入函数就执行,不要在回调函数中执行。
回调中的无效。
无效案例
aliPay(){
	let winRef = window.open('', '_blank');
	let res = await uni.request({
		method: "POST",
		url: xxxx,
		header: {
			authorization: xxxx
		},
		data: {
			amount: xxxx
		},
		success(res){
			window.open(res.data.url);
		}
	});
}

有效案例
aliPay(){
	let winRef = window.open('', '_blank');
	let res = await uni.request({
		method: "POST",
		url: xxxx,
		header: {
			authorization: xxxx
		},
		data: {
			amount: xxxx
		},
		success(res){
			window.open(res.data.url);
			winRef.location = res.data.url;
			uni.request({
				method:"GET",
				url:res.data.url
			})
		}
	});
}
;