Home > Back-end >  How can I replace Current page with another page then open current page in another tab
How can I replace Current page with another page then open current page in another tab

Time:08-31

Hello my Wonderful Developers, I need help on this

Let say my website is https://nkiri.pw/ and I want to click on a button or Link, I want my current page to be replace by this page https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3 and my present page should open another page automatically. How can I achieve this successfully ?

CodePudding user response:

You are using a hyperlink. So you have a href="" in your html tag. You can also set the target (where the page should be opened) to _blank. This means, that the page will be opened in another tab. So if you write it like this: href="https://nkiri.pw/" target="_blank", it will open your current page in another tab. Then you can open the new page with js.

let linkElement = Document.getElementById("yourIdOfTheLinkElement");
linkElement.addEventListener(function () {
 window.open("https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3", "_self");
});

CodePudding user response:

I was able to solve it by doing this:

<a role="button" id='mike' href="<?php echo "https://".$_SERVER['SERVER_NAME']."/" ?>" target="_blank" >Primary</a>

<script>let linkElement = document.getElementById("mike"); linkElement.addEventListener("click", openNew);function openNew() {window.open("https://itinerarycarter.com/h9xdx19n?key=2053deb616c8b3ac8566b44a8ec7c092", "_self");}</script>
  • Related