I'm using the latest stable Chrome, version 41 . I have an open websocket connection on the page and a link to an email address (mailto:***). When the user clicks on the email address the websocket connection is closed. Firefox doesn't have this issue. Do you know how to fix this?
Thank you
For whatever reason, when you click a mailto: link on the same page, Chrome and Firefox will kill any open websockets (and possibly any active XHR connections).
So to get around this, you can hijack the click and call window.open(hrefMailtoTarget). This will leave your connections open and start the user's email client, but you'll notice that you now have a new blank browser page, so you might try window.open(hrefMailtoTarget).close(), which will immediately close that newly opened browser page... but it won't open the email client.
So to globally fix all email links with jQuery:
$(document).on('click', 'a[href^="mailto:"]', function (e) {
e.preventDefault();
var emailWindow = window.open($(e.currentTarget).attr('href'));
setTimeout(function () {
emailWindow.close();
}, 500); // Is half a second long enough?
// I don't know.
// I'd set it as long as you can stand.
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With