1

I'm using JavaScript mailto function and when clicking on the button the mail loads in the same tab. How can I load the mail in a new tab?

Here's my code:

<input type="button" value="Apply" name="apply" onclick="mailJob('Sample');">
function mailJob(code)
{
    window.location="mailto:example@gmail.com?subject="+code;
}
Nikola K.
  • 7,093
  • 13
  • 31
  • 39
I'm nidhin
  • 2,592
  • 6
  • 36
  • 62
  • read here: http://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab – Yan Berk Jul 21 '12 at 19:18

2 Answers2

4

Use window.open function.

window.open('mailto:example@gmail.com?subject='+code, '_blank')

Read more here.

Nikola K.
  • 7,093
  • 13
  • 31
  • 39
0

window.location will redirect the current page to the indicated url. In order to open a new window or tab, you need to do window.open, as is shown in answer that Yan linked to.

hgolov
  • 650
  • 1
  • 11
  • 28