2

I am trying to call a mailto: URI which is stored in a variable. When I do window.location.href = mailto_link; Firefox gives me the following error:

NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057        
(NS_ERROR_ILLEGAL_VALUE) [nsIDOMLocation.href] 

window.location.href = mailto_link;` 

What IE says:

Object doesn't support this property or method

The code works in Chrome but not in IE nor Firefox.

my original function:

function email()
{
    var nom = $('#nom').val();nom = encodeURIComponent(nom);
    var compagnie = $('#compagnie').val();compagnie = encodeURIComponent(compagnie);
    var rue = $('#rue').val();rue = encodeURIComponent(rue);
    var ville = $('#ville').val();ville = encodeURIComponent(ville);
    var province = $('#province').val();province = encodeURIComponent(province);
    var cp = $('#cp').val();cp = encodeURIComponent(cp);
    var remarques = $('#remarques').val();if(remarques ==""){remarques = "Aucune remarque.";}remarques = encodeURIComponent(remarques);
    var quantite = $('#quantite').val(); 
    var email= "someEmail@somedomain.com";
    var subject= "Nouvelle commande";
    var body_message= "%0D%0D%0D%0D"+nom+"%0D"+compagnie+"%0D"+rue+"%0D"+ville+", "+province+"%0D"+cp+"%0D%0D%0DRemarques:"+remarques+"%0D%0D Quantit%E9:"+quantite;
    var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;
    window.location.href = mailto_link;
}

UPDATE 1

I found out what was causing the issue for IE, although I am still looking to resolve it for Firefox. The problem for IE was that I had a console.log(); which wouldn't be recognized (IE8 and lower versions).

Here is a console.log() of the content of mailto_link:

mailto:someEmail@someDomain.com?subject=Nouvelle commande&body=Charger %0Dmodems des %CEseulement%0D%0D%0D%0Djshad%0Daskjda%0Daskdj%0Daskdj, askdj%0DJ9P%204A1%0D%0D%0DRemarques:asldk%0D%0D Quantit%E9:14 
Jeff Noel
  • 7,500
  • 4
  • 40
  • 66
  • Edit: Just tried it on Mac, and it worked for Firefox and Chrome. Can't test IE...you sure there isn't something in the variables? – romo Nov 19 '12 at 18:05
  • What error do you get in IE? – Lee Taylor Nov 19 '12 at 18:12
  • Exactly what are the values of the "email", "subject", and "body_message" variables? You should probably be using `encodeURIComponent()` on those values. – Pointy Nov 19 '12 at 18:18
  • I use `encodeURIComponent()` everywhere (as you can see with the newly edited question). – Jeff Noel Nov 19 '12 at 19:13
  • 1
    There seems to be some sort of problem with how Firefox is handling extended characters in URLs. The problem disappears if you remove the `%CE`(Î) and `%E9`(é) from your logged example. Unfortunately, the only workaround I can think of requires manually replacing extended characters like those with their equivalent HTMLEntities. Since there is no native function to do so in Javascript, that could get quite annoying. – joequincy Nov 19 '12 at 20:07
  • @joequincy By searching a little bit through Stack Overflow I fell on this: http://stackoverflow.com/a/5912746/1451422 Which may suit me for the small web application I have to do. It is quite sad that Firefox does not support localized characters (even encoded). You may want to put your comment as an answer to the question if you wish! – Jeff Noel Nov 19 '12 at 20:15

2 Answers2

1

Firefox is apparently unable to handle the ISO 8859-1 characters above 128 in URLs. The problem disappears if you remove the %CE(Î) and %E9(é) from your logged example. Unfortunately, the only workaround I can think of requires manually replacing extended characters like those with an equivalent (perhaps HTMLEntities*). Since there is no native function to do so in Javascript, that could get quite annoying.

**Because HTMLEntities are only rendered properly in an HTML context, and mailto: URIs produce a plain-text message body, this is an imperfect solution. Below is a function that will do this, but the message will have instances of é and the like. Perhaps a more convenient solution is to convert accented characters to their equivalents in the first 128 ASCII characters as you mentioned in the comments.*


function encodeISO8859 (str) {
    var rstr="";
    for(var i=0; i<str.length; i++) {
        var c = str.charCodeAt(i);
        if(c>191&&c<=255&&!(c==215||c==247)){
            console.log(c);
            rstr += "&#"+c+";";
        } else {
            rstr += str.charAt(i);
        }
    }
    return rstr;
}

This will turn any character in the ISO8859-1 character set (see bottom of page) into its equivalent HTMLEntity. Use this BEFORE encoding for URI:

var nom = $('#nom').val();nom = encodeURIComponent(encodeISO8859(nom));

Of course, only do this if the accented characters are absolutely necessary for comprehension, and there's likely to be overlap between many accents that use the same base character (like A).

Community
  • 1
  • 1
joequincy
  • 1,395
  • 10
  • 21
0

I tried this and it worked for me, but I think the error code is probably related to one of the addons you may have Installed in firefox or IE, restarting the browser should help.

this is probably caused by an addon / userscript which is doing some operations/modifications on the page while google redirects you do a search result. you can try to run firefox in Troubleshoot Firefox issues using Safe Mode and see if the error still occurs there. if not disable all your addons & reenable them one in order to find out which one is causing it exactly (you'll likely have to do a restart of the browser after each one).

MORE

defau1t
  • 10,593
  • 2
  • 35
  • 47
  • It didn't change the situation for Firefox (sadly), and IE had a different issue which is now fixed. Thanks for your contribution though. – Jeff Noel Nov 19 '12 at 19:59