Search code examples
javascripthtmlwebkitmailto

Webkit Browsers (Chrome and Safari) don't like mailto?


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.com/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.


Solution

  • try window.location.href='mailto:[email protected]'; ;)

    works for chrome 12 ;) haven't tested it in safari :)