Why do mailto links in Chrome conflict with POST requests?

I'm not quite sure that the question is correct, but here is the situation. I have a webpage with two POST requests that have been open for some time (the answer is not expected right away), while I can do other things on the page. I also have a mailto link on the page. For some reason in Chrome, when I click this link, two requests immediately return an error. I also noticed that the console in Chrome shows the mailto link as a GET request event (when it is clicked). What's going on here? Even if Chrome treats mailto links as requests, why should it conflict with any other requests on the page?

In Firefox, the mailto link has zero effect on requests, they just continue to work and wait for a server response. Also, the link itself does not seem to be a request of any kind. BTW, mailto opens the Outlook message box (and this part works fine in Chrome, just the requests don't work).

Also, just in case, I use jQuery $ .ajax to run queries.

It has been pointed out that, perhaps, Chrome considers the mailto link as normal, at least in part, and therefore has some side effects. So the question is, how can I combine the mailto link with the request on the page? I can not replace the link to the form.

+7
source share
5 answers

I recently ran into this problem. This actually happens with mailto: or any other application URI in Chrome. The solution I used was to load the url in the iframe:

$('body').append('<iframe id="mailto-launcher"></iframe>'); $('#mailto-launcher').get(0).contentWindow.location.href = 'mailto:?subject=test'; 

You can also configure the iframe to appear on the page (using absolute positioning, etc.). This will start the mail client and save your documents AJAX requests.

+7
source

Google Analytics support offers to capture links, send a request to GA, wait 100 ms and then update the URL. 100 ms should be sufficient to complete the tracking request. https://support.google.com/analytics/answer/1136920?hl=en

The example is inconvenient, the next one is a modified version that automatically processes all links (also created using javascript / loaded using AJAX):

 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script> function trackOutboundLink(event){ var url = event.currentTarget.href; try { _gaq.push(['_trackEvent', 'Outbound Links' , url]); } catch(err){} setTimeout(function() { document.location.href = url; }, 100); return false; } $(document).on('click', 'a[href]', trackOutboundLink); </script> 
+1
source

Not sure, but it is possible that Chrome accesses mailto links when going to a new page.

It has all the side effects, but none of the real effects (for example, reloading the page).

0
source

This issue prevented me from sending an event to Google Analytics when an email link was clicked.

As a workaround, I changed the purpose of mailto: links to _blank. This forces the browser to open a blank tab before opening Mail.app, but now GA integration works.

0
source

Same thing, POSTs on mixpanel have been canceled. Our workaround was to call mailto: link using setTimeout for 1 second, this works just fine. Not beautiful, tough, but at 10 pm on Friday in the office it sounded kind of like :)

0
source

All Articles