open email client through javascript
Asked Answered
F

2

9

is there anyway through which I can open more than one email client, (on a single click) in java script, I know how to use mailto but don't know how to open multiple clients this code opens the client on each reload.

window.location.href = "mailto:[email protected]?subject=Subject&body=message%20goes%20here";

Any help in this regard Thanks

Fredette answered 8/4, 2014 at 15:28 Comment(0)
C
11

If you want it to load the mail client on a click rather than every time the page refreshes, you want it attached to a click event, something like this :

<button class="button">Open Email</button>

Using jQuery :

$(document).ready(function(){
    $('.button').on('click',function(){
       window.location.href = "mailto:[email protected]?subject=Subject&body=message%20goes%20here"; 
    });
});

Update

If you want it to load multiple instances of the client, just duplicate the window.location.href :

$(document).ready(function(){
    $('.button').on('click',function(){
       window.location.href = "mailto:[email protected]?subject=Subject&body=message%20goes%20here";
       window.location.href = "mailto:[email protected]?subject=Subject2&body=message%20goes%20here";
    });
});
Ceyx answered 8/4, 2014 at 15:33 Comment(8)
i want to launch it more than onceFredette
Yes working ok in Firefox. What browser are you using?Ceyx
I am using Google chromeFredette
Try this one for chrome, i've added a slight delay on the second open.. jsfiddle.net/G7Ws7/2Ceyx
Looks like chrome doesn't like window.location.href being fired twice by one event. Will only fire the second one. And won't fire on a setTimeout. I'll try a few more things see if we can work around this.Ceyx
so there is no patch for Google Chrome?Fredette
I haven't managed to find a fix as of yet I'm afraid! I will try and look a bit further into it tomorrow!!Ceyx
All the above Fiddle links are broken, Error 404 not foundAssemblyman
M
1

It is not possible to launch external applications from JavaScript in a Browser. mailto only launches the MUA which is configured as the default in the system-settings.

Missy answered 8/4, 2014 at 15:30 Comment(3)
i meant the same, launching more than 1 default client on single clickFredette
At the risk of sounding.. thick, what is MUA ?Nudibranch
MUA stands for Mail User AgentMissy

© 2022 - 2024 — McMap. All rights reserved.