Below is my code:
function email(from, to, subject, body){
if(subject == "Website Feedback"){
to = to + "; [email protected]";
}
if(from == "Outlook" || from == "LiveDesk"){
window.location="mailto:"+to+"?subject="+subject+"&body="+body;
}else if(from == "Gmail"){
window.location=";tf=0"+to+"&su"+subject+"&body"+body;
}
}
^^ Javascript for the below HTML
<div id="hiddenForm">
<form>
What do you use for your email? <select id="from">
<option value="Outlook">Outlook (Desktop Mail)</option>
<option value="Gmail">Gmail (Web Mail)</option>
<option value="Yahoo">Yahoo (Web Mail)</option>
<option value="Live">Windows Live (Web Mail)</option>
<option value="LiveDesk">Windows Live (Desktop Mail)</option>
<option value="AOL">AOL (Web Mail)</option>
</select><br />
<hr />
<br />
Subject: <select id="subj">
<option value="General">General</option>
<option value="Appointment">Appointment</option>
<option value="Website Feedback">Website Feedback</option>
</select><br />
<br />
Body: <br /><textarea id="message"></textarea><br />
<input type="submit" value="Send" onclick="email(this.form.from.value, '[email protected]', this.form.subj.value, this.form.message.value)" />
</form>
</div>
The problem I am having is that in Internet Explorer and Firefox, this code works perfectly. In Safari and Chrome, it won't work. It basically just reloads the page, but nothing happens. As you can see, its only set up to work with Outlook and Live (desktop version) using mailto. Gmail I'm not sure works yet. If anyone can help me to know why the webkit browsers aren't recognizing this code, please do.
Below is my code:
function email(from, to, subject, body){
if(subject == "Website Feedback"){
to = to + "; [email protected]";
}
if(from == "Outlook" || from == "LiveDesk"){
window.location="mailto:"+to+"?subject="+subject+"&body="+body;
}else if(from == "Gmail"){
window.location="https://mail.google./mail?view=cm&tf=0"+to+"&su"+subject+"&body"+body;
}
}
^^ Javascript for the below HTML
<div id="hiddenForm">
<form>
What do you use for your email? <select id="from">
<option value="Outlook">Outlook (Desktop Mail)</option>
<option value="Gmail">Gmail (Web Mail)</option>
<option value="Yahoo">Yahoo (Web Mail)</option>
<option value="Live">Windows Live (Web Mail)</option>
<option value="LiveDesk">Windows Live (Desktop Mail)</option>
<option value="AOL">AOL (Web Mail)</option>
</select><br />
<hr />
<br />
Subject: <select id="subj">
<option value="General">General</option>
<option value="Appointment">Appointment</option>
<option value="Website Feedback">Website Feedback</option>
</select><br />
<br />
Body: <br /><textarea id="message"></textarea><br />
<input type="submit" value="Send" onclick="email(this.form.from.value, '[email protected]', this.form.subj.value, this.form.message.value)" />
</form>
</div>
The problem I am having is that in Internet Explorer and Firefox, this code works perfectly. In Safari and Chrome, it won't work. It basically just reloads the page, but nothing happens. As you can see, its only set up to work with Outlook and Live (desktop version) using mailto. Gmail I'm not sure works yet. If anyone can help me to know why the webkit browsers aren't recognizing this code, please do.
Share Improve this question asked Jun 17, 2011 at 13:29 banjokaboombanjokaboom 1342 silver badges16 bronze badges 4- I'm not sure about browsers, but I know I don't like mailto links! SCNR – Tim Büthe Commented Jun 17, 2011 at 13:32
-
Please note this: Using
mailto
requires that the puter that the user is using has a mail client configured. Today many users use a web client and therefore it won't work. A much better solution is to send the form back to your server (usingmethod='post'
in the form-tag) and process the data there. It is also much faster since you don't have to wait for the mail to go through all the mail servers before if es back to you. – some Commented Jun 17, 2011 at 13:43 - Yeah i understand that. For testing purposes and just for now I want to make sure that I can build the email from this. Down the road when this bees a server application I will take that into consideration and refactor my code accordingly. For now though I am just testing it on my puter where I have a desktop client set up. – banjokaboom Commented Jun 17, 2011 at 13:49
- It's your decision, but my opinion is that you're wasting your time with methods that where obsoleted about 15 years ago. You can download a plete web-server with script- and database-capabilities in a single package. With that you can write code that you can move to the real server when it's finished and you only have to edit a configuration file to get your application to use the right resources on the real server. – some Commented Jun 17, 2011 at 14:03
2 Answers
Reset to default 4try window.location.href='mailto:[email protected]'; ;)
works for chrome 12 ;) haven't tested it in safari :)
Thanks for great help I have done finally with some help from above code.
function mailURL(url)
{
var mailto_link = 'mailto:'+'?subject='+document.title+'&body='+escape(url);
if(getBrowser()=='mozilla'){
// Mozilla FireFox Mail To Friend
// Opens a new tab but also opens up Microsoft Office window with URL
window.open(mailto_link,'emailWindow');
}
else if(getBrowser()=='ie'){
// IE Favourite
window.open(mailto_link,'emailWindow');
}
else if(getBrowser()=='opera'){
// Opera
return true;
}
else if (getBrowser()=='safari'){ // safari
window.location.href=mailto_link;
//alert('mail to safari');
}
else if(getBrowser()=='chrome'){
window.location.href=mailto_link;
//alert('mail to chrome');
}
}
function getBrowser(){
var userAgent = navigator.userAgent.toLowerCase();
$.browser.chrome = /chrome/.test(userAgent);
$.browser.safari= /webkit/.test(userAgent);
$.browser.opera=/opera/.test(userAgent);
$.browser.msie=/msie/.test( userAgent ) && !/opera/.test( userAgent );
$.browser.mozilla= /mozilla/.test( userAgent ) && !/(patible|webkit)/.test( userAgent ) || /firefox/.test(userAgent);
if($.browser.chrome) return "chrome";
if($.browser.mozilla) return "mozilla";
if($.browser.opera) return "opera";
if($.browser.safari) return "safari";
if($.browser.msie) return "ie";
}