how to make a pop under tab in mobile version

34 Views Asked by At

I am working on a given task , firstly i had a task to do , when the main page refreshes or reloads (..ex index.html) , to pop a tab under the index , and the focus to be stayed on index file , but i did that , now i have to do the responsive version , in mobile im having a issue , because i think is impossible i've been trying to do for weeks and couldn't find an answer. If anyone on you can view my code and help me pop under a tab in mobile version (when i refresh index , i still need to be stayed on index , just another tab added). Thank you!

  let url = "http://youtube.com";
  let newWindow = window.open(
    url,
    "_blank",
    "resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no"
  );
  if (newWindow) {
    newWindow.blur();
    newWindow.addEventListener("focus", function () {
      newWindow.blur();
    });
    newWindow.addEventListener("blur", function () {
      window.focus();
    });
  }

  if (newWindow) {
    requestFullscreen(newWindow);
  }

  function requestFullscreen(element) {
    if (element.requestFullscreen) {
      element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
      // Firefox
      element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
      // Chrome, Safari and Opera
      element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
      // IE/Edge
      element.msRequestFullscreen();
    }
  }

  if (window.innerWidth <= 600 || mobile) {
    console.log(window.innerWidth, "the width of the actual mobile window");
    document.body.style.backgroundColor = "red";

    window.addEventListener("load", function () {
      window.focus();

      setTimeout(function () {
        let googleTab = window.open("http://google.com", "_blank");
        if (googleTab) {
          setTimeout(function () {
            googleTab.close();
            window.focus();
          }, 100);
        }
      }, 500);
    });
  } else {
    let MINUTE_MILLISECONDS = 60000;
    let now = new Date().getTime();

    if (
      !localStorage.t ||
      now > parseInt(localStorage.t) + MINUTE_MILLISECONDS
    ) {
      localStorage.t = now;
      window.location.href = "http://youtube.com/";
      window.open(window.document.URL, "_blank");
    }

    window.addEventListener("beforeunload", function () {
      localStorage.clear();
    });
  }`

, As you can see in my code , i opened a google.com tab fast and closed just to try to switch the focus to main page , and then create a new youtube.com tab , but it didnt work , i've been trying it so hard but i can't, if anyone can view this in mobile version , and answer me , would be so helpful ,

  • ONLY TEST FOR MOBILE VERSION (Desktop version is done)
0

There are 0 best solutions below