|
It's quite simple to display an Email link for sending a page or a link to someone else:
<a href="mailto:?subject=Web Address&body=This might interest you: http://www.bme.ie">Send BME Web Address to a Friend</a>
The
mailto: protocol is used. This simply starts the user's Email client program with the given parameters for the Email
subject and the Email
body. Since there is no web address for the recipient specified between
mailto: and
?, the user can fill this in (e.g., with some address from her/his address book).
The following JavaScript code takes this a bit further:
var sSubject = 'Interesting Web Page';
var sBody = 'Hi,\\n\\nthis might interest you:\\n' + location.href;
var sDisplay = 'Send this Page to a Friend';
document.write(
'<a href="mailto:'
+ '?subject=' + escape(sSubject)
+ '&body=' + escape(sBody)
+ '">' + sDisplay + '</a>'
);
In the code above, the
sSubject (subject) and
sBody (body) variables/parameters are encoded with the
escape function to allow for special characters such as newlines to be used without problems.
Working examples:
Send BME Website Link to a Friend
JavaScript Application: Email a Page/Link to a Friend • © 2013 Manfred Baumeister • Updated: 29 October 2008, 14:15 [UTC]
|