Cross Browser Tell a Friend JavaScript

Posted By tomcanji on April 8, 2009

Recently we had a client asking for a “tell a friend” JavaScript that works in all major web browsers.

Why not - how complicate can it be? All I have to do is type something like this in google and I’ll have my “Tell a Friend” working on ie, ie6, firefox, safari in no time… Yeah right.

As you’ve might of guessed that was not the case.

Finally we found something that works so here it is

Copy the js code blelow

<SCRIPT TYPE="text/javascript">

var SubjectLine='Take a look at this web page I found, '+top.document.title;
var BodyText='You can see this page at: '+top.location.href;

var Message='Send <A CLASS=contact HREF="mailto:?SUBJECT='+escape(SubjectLine)+'&BODY='+escape(BodyText)+'" TITLE="Send your friends e-mail about this page">this page<\/A> to a friend.';

var MessageIE='Send <A CLASS=contact HREF="mailto:?SUBJECT='+(SubjectLine)+'&BODY='+(BodyText)+'" TITLE="Send your friends e-mail about this page">this page<\/A> to a friend.';

if(document.all) { document.write(MessageIE); }

else { document.write(Message); }

</SCRIPT>

paste this code on the place you want your “Tell a Friend” link to appear

About the author

tomcanji

While many people come and go from Array Studio, he is here to stay – for more then 3 years now. Dedicated professional with a sharp eye for every detail. Recently he started with Web Design as well.

Comments

6 Responses to “Cross Browser Tell a Friend JavaScript”

Dusan Belic says:
April 9th, 2009 at 12:27 am

Heh. Kad predjes misem preko linka u statusbar-u pise na francuskom, a title (kad malo duze drzis mis na linku) je na engleskom. Ovo je ujedno alatka za ucenje jezika. :)

Hi Dusan, thanks for noticing :)

I have fixed this issue. There have also been some bugs concerning the title of “tell a freind” email - this has also been fixed.

bro wat sapp… i want 2 ask u bout disable ctrl + a,c,j,n for ie can work but not realy work in fire fox how.??/ email me.. shahril143@gmail.com

Add a Comment