skip to Main Content

enter image description here

Here in the image as you can see it is preventing me from opening a new tab due to pop-blocker , but the task is to create it without even enabling it , just something like forcefully , i’ve tried a lot of codes , but still it didn’t open a new tab , i need 2 tabs , 1 should be index.html , and the other one should be the link for example http://youtube.com

i’ve tried this code , but it works only when i Allow the Pop-up Blocker

     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();
        }
      });

This code below this text also goes from index.html for example to blancashrimp , but it doesnt open a new tab
just it changes the link without opening a new tab

 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);
};

Can yall help me figure it out , is it impossible to do it or what

* NOTE THROUGH JAVASCRIPT ONLY

2

Answers


  1. It is impossible to do this, with pop-up blocker enabled. And for good reason.
    Browser developers work hard to prevent unwanted behavior you request.
    I suggest you do not try to bypass it.

    Login or Signup to reply.
  2. ok, first of all, this i generally unwanted behaviour from a website. with that said

    let form = document.createElement("form")
    form.method="GET"
    form.action="https://google.com/"
    form.target="about:blank"
    form.style="display:none"
    document.body.appendChild(form)
    form.submit()
    form.remove()
    

    no guarantees

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search