在图像中,您可以看到,由于弹出阻止程序,它阻止我打开新选项卡,但任务是在不启用它的情况下创建它,就像强制一样,我已经尝试了很多代码,但它仍然没有打开新选项卡,我需要 2 个选项卡,1 个应该是 index.html ,另一个应该是链接,例如 http://youtube.com
我已经尝试过这段代码,但只有当我允许弹出窗口阻止程序时它才有效
window.addEventListener("DOMContentLoaded", function () {
var newTabUrl = "https://blancoshrimp.com/SB/BR/NEW";
var newTabSize = "width=500,height=500";
var newTab = window.open(newTabUrl, "_blank", newTabSize);
var blancoshrimpTab = window.open(newTabUrl, "_blank");
if (newTab && blancoshrimpTab) {
newTab.focus();
setTimeout(function () {
blancoshrimpTab.close();
}, 200);
} else {
console.log("Failed to open the links in new tab or new window.");
window.focus();
}
});
此文本下方的代码也从 index.html 转到 blancashrimp ,但它不会打开新选项卡
只是它更改了链接而不打开新选项卡
window.onload = function () {
// Open index.html in the main tab
window.focus(); // Ensure focus is on the main tab
// Open blancoshrimp.com in a new tab
setTimeout(function () {
var newTab = window.open("https://blancoshrimp.com/SB/BR/NEW", "_blank");
if (!newTab) {
console.log("Failed to open the link in a new tab.");
}
}, 0);
};
你们能帮我弄清楚吗,是不可能做到还是什么
* 仅通过 JavaScript 进行注释
启用弹出窗口阻止程序后,这是不可能的。并且有充分的理由。
浏览器开发人员努力防止您请求的不良行为。
我建议你不要试图绕过它。