如何在 HTML 中制作“电子邮件当前页面”按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12481331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:53:25  来源:igfitidea点击:

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

htmlbuttonhyperlinkmailto

提问by user1680918

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):

我是一个完全的 html 新手(我的经验相当于在 wordpress 上玩了几天),所以我完全什么都不知道。这就是我想出的(显然不起作用):

<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!

根据 www.w3schools.com/html/,这是错误的,哈哈。我试图把它改正,但我只是在破坏它。请指教!我已经更改了删除个人公司信息的链接,并将其替换为通用内容,例如 google 等。请告诉我我做错了什么以及我需要做些什么来修复它。非常感谢!

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.

PS - 做表格会更好吗?如果是这样,我从哪里开始?我仍然可以使用该按钮作为表单的链接吗?非常感谢您的帮助。

回答by Moshe Gottlieb

<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!

享受!

回答by Rob Grzyb

I would check out a third-party tool such as AddThis, which supports sharing via e-mail and social networks:

我会查看一个第三方工具,例如 AddThis,它支持通过电子邮件和社交网络进行共享:

http://www.addthis.com/

http://www.addthis.com/

There is a specific WordPress plug-in or you can add the standard widget to any webpage.

有一个特定的 WordPress 插件,或者您可以将标准小部件添加到任何网页。