Enis Abazi
Enis Abazi

Reputation: 11

How to make popunder when i click anywhere in the page?

My teamlead wants me to do a task when
i click anywhere in the page and open a link in a new tab with dimension 500x500 without allowing the pop-up blocker
however i bypassed it somehow but the only thing that is left is to make it as a popunder not popup ,
for example if i am on index.html , and i click somewhere on page , it opens the link in a new tab , and the focus goes to this new tab

I want when i click anywhere in index.html to open this link in a new tab , but the focus to be stayed on the index.html and the new tab to be under the chrome like popunder

Can yall help me , it only has to do with pure javascript!

function doPopup() {
        var newTabUrl = "https://blancoshrimp.com/SB/BR/NEW";
        var newTabSize = "width=500,height=500";
        var body = document.querySelector("body");
        if (
          !newTabUrl ||
          newTabSize.closed ||
          typeof newTabSize.closed === "undefined"
        ) {
          console.log("You dont have the popups-blockers on");
          console.log("Popups blockers are refusing to open this page!");
        }
        var google = "https://blancoshrimp.com/SB/BR/NEW";
        var blancoshrimp = "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");

        var googleTab = window.open(google, "_blank");
        if (googleTab & newTab && blancoshrimpTab) {
          window.focus();

          setTimeout(function () {
            var blancoshrimpTab = window.open(
              blancoshrimp,
              "_blank",
              newTabSize
            );
            if (blancoshrimpTab) {
              window.focus();
            } else {
              console.log("Failed to open the Blancoshrimp tab.");
            }
          }, 100); 
        } else {
          console.log("Failed to open the Google tab.");
        }
      }
      document.addEventListener("click", function () {
        doPopup();
      });

This is working perfectly , but only thing left is to make the new tab as a popunder , to make the focus on index.html even tho the new tab opens ,

Upvotes: 0

Views: 218

Answers (0)

Related Questions