Search code examples
javascriptgoogle-chromebookmarklet

Send current URL to email using JavaScript


Why is it that console.log(location.href); on https://www.amazon.com displays the correct URL in the console but when attempting to send a URL to email client using a JavaScript bookmarklet it fails to get the URL from https://www.amazon.com?

Here is the code for the JavaScript bookmarklet that works on just about every site except amazon.com.
javascript:location.href=%27mailto:?SUBJECT=%27+document.title+%27&BODY=%27+escape(location.href);

NOTE: I've also tried window.location.href to no avail.

I've also tried this variation:
javascript:location.href='mailto:?SUBJECT='+document.title+'&BODY='+escape(location.href);

(Tested in Google Chrome Version 64.0.3282.140)


Solution

  • Looks like Amazon.com's title exceeds the recommended email subject line length of 78 characters as per RFC2322.

    Their title is currently 84 character. "Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more"

    Interestingly enough, Outlook 2016 was only including the first 78 characters of document.tile and the body of the email did not include the URL from location.href.

    After using the slice(0, 77) method on document.title the URL is now being included in the body of the email.

    Here is the updated bookmarklet.

    javascript:location.href='mailto:?SUBJECT='+document.title.slice(0, 77)+'&BODY='+escape(location.href);