MailTo From Javascript

I've got a link button which is used to build up a mailto from the contents of the page. What is the best way to launch it from javascript without opening a blank window or disturbing the window it's called from?

function Email()
{
    var sMailTo = "mailto:";
    var sBody = "";

    var alSelectedCheckboxes = new Array();
    $("input:checkbox[CheckBoxType=Email]:checked").each(function()
    {
        alSelectedCheckboxes.push($(this).val());
    });

    if (alSelectedCheckboxes.length > 0)
    {
        for (var i=0; i<alSelectedCheckboxes.length; i++)
        {
            sBody += alSelectedCheckboxes[i];
            sBody += "\n";
        }

        sMailTo += escape("<Insert Recipients Here>") +"?subject=" +escape("<Insert Subject Here>") +"&body=" +escape(sBody);
        window.location.href = sMailTo;
    }
    else
    {
        alert("Please select some results");
    }
}

The simple function is above. window.location.href doesn't work properly unless it's Firefox/Chrome (it redraws the page in IE8). I've also tried window.open(sMailTo, "_self") but again in IE8 this breaks the page that it's called from.

I'm sure this is a stupid question.... :-)

Thanks

14
задан Gordon Thompson 10 March 2011 в 20:02
поделиться