0

Following js code refreshing the page to the url, but i wanna make it open in a new tab.

    case"example1":  case"example2":
     l.after('<meta http-equiv="refresh" content="0; url=https://example.com" /> Opening...'); ```
Can anyone help me about that?

1 Answers1

-1

Steps for opening a link in a new tab:

  1. Create an a element
  2. Set the href ( "https://example.com" )
  3. Set target to "_blank"
  4. Click on the link

Code:

<button onclick="myFunction()">Open</button>
<script>
function myFunction() {
  link = document.createElement("a")
  link.href = "https://example.com"
  link.target = "_blank"
  link.click()
}
</script>
RixTheTyrunt
  • 185
  • 3
  • 11