-5

hey I need help with this code I want the link to open in a new tab instead i want the link to be opened in new tab instead of the current one

    <form>
<input class="MyButton" type="button" value="Your Text Here" onclick="window.location.href='http://www.yourdomain.com'" />
</form>
  • 1
    Does this answer your question? [Open a URL in a new tab (and not a new window)](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window) – DBS Jan 20 '21 at 14:54
  • 2
    Is there any reason you're using a form rather than a [button](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) or an [a tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a)? You could likely use an a element with a target of _blank instead. – Minion3665 Jan 20 '21 at 14:56

3 Answers3

0

In order to target new window you need to make use of target="" property Also window.location.href contains link of current url.

<form>
<input class="MyButton" type="button" value="Your Text Here" onclick="window.location='http://www.yourdomain.com'" target="_blank"/>
</form>
Jayr
  • 592
  • 1
  • 3
  • 14
0

If you want to use Javascript use: WINDOW.OPEN

<form>
<input class="MyButton" type="button" value="Your Text Here" onclick="window.open('http://www.yourdomain.com')" />
</form>
Mohcin Bounouara
  • 593
  • 4
  • 18
0

Hey to make the link open in new tab you have to add target= "_blank"

Like this

  <form>
<input class="MyButton" type="button" target="_blank" value="Your Text Here" onclick="window.location.href='http://www.yourdomain.com'" />
</form>
Rockzy
  • 65
  • 8