I'm trying to open the local mail window using the javascript window.location.href=mailto:<addresses>
. However, my addresses exceed the maximum length. So I slice it into pieces, and send these one after the other, after a specific timeout. However, the second relocation will not open a new (Outlook) mail window if the first is still open... Is there any way to get around this? Or is there another/better way to open multiple mail windows on the local client?
Any help would be greatly appreciated!
The code:
function Send_Mails(mails) {
var timeout = 2000;
var maxUrlCharacters = 1900;
var currIndex = 0;
var nextIndex = 0;
if (mails.length < maxUrlCharacters) {
window.location = 'mailto:' + mails;
return;
}
do {
currIndex = nextIndex;
nextIndex = mails.indexOf(';', currIndex + 1);
} while (nextIndex != -1 && nextIndex < maxUrlCharacters)
if (currIndex == -1) {
window.location = 'mailto:' + mails;
} else {
window.location = 'mailto:' + mails.slice(0, currIndex);
setTimeout(function () {
Send_Mails(mails.slice(currIndex + 1));
}, timeout);
}
}
This opens the first mailwindow correctly, but the second one is never opened as long as the first one is open.
Best regards, Hans
The sample script below works for me on
localhost
When on Fiddle, it seems to be working 75% of the time (with ad blocker turned on).
There is a risk that popup and ad blockers, anti-virus software etc. may silently block forced opening of multiple mailto links.