1

I need to use window.location.href to open the user's email so for that I have the following code:

$("#email").click(function(){
      window.location.href = "mailto:myemail.com?subject=Subject&body=xxxxxxxxxxxxxxxxxxxxxxxxxxx";

});

Which works fine. However, the problem is I cannot open the user email page in a new tab and it opens by redirecting the current page which is not user friendly. How can I achieve this?

Hamed Minaee
  • 2,480
  • 4
  • 35
  • 63
  • What do you mean by "user email page"? The user might have an email program that opens outside the browser (e.g., Outlook). Why don't you just have `Email`? – nnnnnn Feb 24 '17 at 02:49

4 Answers4

1

You're looking for window.open()

Example:

window.open("mailto:myemail.com?subject=Subject&body=xxxxxxxxxxxxxxxxxxxxxxxxxxx");

Josh
  • 1,455
  • 19
  • 33
1

You can use the target="_blank" attribute on any regular anchor tag to make sure that the link is opened in a new tab, without using any JavaScript. Note, however, that mailto links are often handled by browsers specially and may just redirect to the system's default mail app without opening a visible tab.

<a id="email" target="_blank" href="mailto:person@example.com?subject=Subject&body=Body">
  Email us!
</a>

Edit: It looks as if this method won't work in certain versions of Firefox, due to a bug. (See this answer.)

Community
  • 1
  • 1
gyre
  • 16,369
  • 3
  • 37
  • 47
0

Have a look at this: Open the href mailto link in new tab / window

You can't open a 'mailto' link in new tab/window by default.

You need to use window.open() in your click override.

Community
  • 1
  • 1
Amir
  • 232
  • 3
  • 11
0

please check below link and you can view the demo using this link.

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open

arun d
  • 229
  • 1
  • 3
  • 10