0

I have a link href built with html, but this link i will open with left button mouse it will open in the same page, that is the wrong i need to open in other tab, so i want to open in another tab

const url = `https://shiene/mk/${number}`
const ref = "<a href='" + url + "'>" + 'Go' + '</a>'

i saw others answers but they solved with click button,

i dont know if its possible solve with html or javascript dont care to me how can i open in other tab?

react1
  • 25
  • 13
  • Just add `target="_blank" rel="noopener noreferrer"` to the link in your javascript, make sure to get the quotes correctly since you are using single quotes – Huangism Dec 14 '21 at 17:20
  • maybe try to use the document.createElement method link: https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement – ShadowLp174 Dec 14 '21 at 17:27

2 Answers2

2

To open a link in a new tab, add target="_blank"

    const url = `https://shiene/mk/${number}`
    const ref = "<a href='" + url + "' target=\"_blank\">" + 'Go' + '</a>'
Deepak
  • 2,660
  • 2
  • 8
  • 23
1

Just add target=“_blank” to the link element and maybe try to use the document.createElement method.
Link: https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
traget attribute: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/target

ShadowLp174
  • 502
  • 2
  • 9