Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an "email current page" button in HTML?

The desired goal: I am trying to make an "email current page" button to go on my website. These are the necessary functions:

  • It should be versatile to match any page the button is on (ie different articles I put up on my site, etc)
  • It should have no recipients set automatically
  • It should have a fixed subject line
  • It should have body text that includes a link to the current page (again, not a fixed link, but a versatile link that adapts to whatever page the button is activated on).
  • Lastly, the email button should be visible on the webpage in the form of an image icon.

I am a total html novice (my experience amounts to a few days of playing around on wordpress) so I know absolutely nothing. This is what I came up with (which clearly doesn't work):

<a href="MAILTO:?subject=Check out this company&body=Check out <a title="this site" href="www.google.com">this company</a>. They are a search engine. I thought this might be of interest to you. " target="_blank"><img src="http://www.ccaa.ca/web/templates/cc… /></a>

According to www.w3schools.com/html/ this was way wrong, lol. I have tried to put it right but I'm just wrecking it more. Please advise! I've changed the links to remove personal company info and replaced it with generic things such as google, etc. Please tell me what I've done wrong and what I need to do to fix it. Thanks so much!

PS - would it be better to do a form? If so, where do I start? Can I still use the button as a link to the form? Many thanks for the help.

like image 495
user1680918 Avatar asked Dec 08 '22 21:12

user1680918


1 Answers

<html>
<head>
    <title>My Page</title>
    <script language="javascript">
        function emailCurrentPage(){
            window.location.href="mailto:?subject="+document.title+"&body="+escape(window.location.href);
        }
    </script>
</head>
<body>
        <a href="javascript:emailCurrentPage()">Mail this page!</a>
<body>
</html>

Enjoy!

like image 101
Moshe Gottlieb Avatar answered Jan 06 '23 05:01

Moshe Gottlieb