Baumeister Mediasoft Engineering BME - Baumeister Mediasoft Engineering  JavaScript Application: Email a Page/Link to a Friend - English Version JavaScript-Anwendung: Seite/Link an einen Bekannten schicken - Deutsche Version
Baumeister Mediasoft Engineering
Bartels AutoEngineerCarLogServicesResourcesCompany ProfileContact Us
Baumeister Mediasoft Engineering » Resources » Web Development » JavaScript » Applications » Email Page/Link
JavaScript Applications

JavaScript Application: Email a Page/Link to a Friend

Baumeister Mediasoft Engineering

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

Related Topics

Baumeister Mediasoft Engineering » Resources » Web Development » JavaScript » Applications » Email Page/Link

JavaScript Application: Email a Page/Link to a Friend • © 2023 Manfred Baumeister • Updated: 29 October 2008, 14:15 [UTC]

Baumeister Mediasoft Engineering, Clontarf, Dublin 3, D03 HA22, Ireland
© 2023 Manfred Baumeister

JavaScript Application: Email a Page/Link to a Friend - English Version JavaScript-Anwendung: Seite/Link an einen Bekannten schicken - Deutsche Version