[英]Window.open popup blocking issue on button click
I want to open two url on one button click. 我想一键打开两个URL。 I have used window.open method but its blocking popup. 我已经使用window.open方法,但是它阻止了弹出窗口。
On button click I want to open this two url. 在按钮上单击我要打开这两个URL。 but it is not working as per need. 但它不能按需工作。
Here is my code for script. 这是我的脚本代码。
<script>
$(document).ready(function() {
setTimeout(function(){
var newUrl = 'https://red.kngtraxx.com/5d2fe6a5180ed400010de4be?fname=' + fname + '&email=' + email + '&clickid=' + clickid + '&pid=' + pid + '&phone=' + phone + '&sub1=' + sub1 + '&edulevel=' + edulevel + '&military=' + military + '&study=' + study + "&ip=" + ip + "&zip=" + zipcode;
var newTabUrl = 'https://red2.kngtraxx.com/5d2fe70e180ed400010de4c0?fname=' + fname + '&email=' + email + '&clickid=' + clickid + '&pid=' + pid + '&phone=' + phone + '&sub1=' + sub1 + '&edulevel=' + edulevel + '&military=' + military + '&study=' + study + "&ip=" + ip + "&zip=" + zipcode;
alert(newUrl);
alert(newTabUrl);
$('#lp-pom-button-826').on('click', function(e){
e.preventDefault();
window.open(newUrl, "_self");
window.open(newTabUrl)
//setTimeout(() => , 1000);
});
}, 2000);
});
</script>
I want to solve popup blocking issue
Try the following, window.open()
will work for one tab, otherwise, it will be blocked. 请尝试以下操作, window.open()
将适用于一个选项卡,否则将被阻止。
<html> <head> </head> <body> <a href="https://google.com" onclick="location.href='https://yahoo.com'" target="_blank">Click Here</a> </body> </html>
<html> <head> </head> <body> <a id="myLink" href="https://google.com" onclick="location.href='https://yahoo.com'" target="_blank">Click Here</a> <script> function makeDynamicUrlsAndChangeLink() { var link = document.getElementById("myLink"); var param1 = "val1", param2 = "val2"; var link1 = "https://google.com" + "?param1=" + param1 + "¶m2=" + param2; var link2 = "location.href='https://vmware.com" + "?param1=" + param1 + "¶m2=" + param2 + "'"; link.setAttribute("href", link1); link.setAttribute("onclick", link2); } makeDynamicUrlsAndChangeLink(); </script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.