Search code examples
javascriptinternet-explorerfirefoxcmdfirefox-addon

Firefox Add-On can't start iexplore URL with parameters via cmd


I am working with Firefox add-ons. I would like to execute IE using this command line:

cmd /C start iexplore http://www.google.com

This works well. But if you have to use parameters, it will not work:

cmd /C start iexplore https://www.google.hu/?gfe_rd=cr&ei=r9frVbawJZChOomkqIgH&gws_rd=ssl#q=find

The problem is that the passed text will be cut off at the first "&" character. If I put the url into quotation mark it works again.

So I use this code to implement the addon:

getIEPath: function () {
        var gMyPrefs = new PrefsWrapper1("extensions.openinbrowser.");
        var iePath = gMyPrefs.getUnicharPref("IEPath");
        return iePath;
    },
    openInBrowser: function (url) {
        var iePath = openinbrowser.getIEPath();

        // create an nsILocalFile for the executable
        var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        file.initWithPath(iePath);

        // create an nsIProcess
        var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        process.init(file);

        // Run the process
        var args = ['/C start iexplore ' + url + ' '];
        process.run(false, args, args.length);
    }

This works for the first case: if there is no "&" character in string it works. But if I exchange the key line to

var args = ['/C start iexplore "' + url + '" '];

it will not work, as the " will be exchanged to URI code, but URI code will not work in IE.

Do you know what is the solution (I know that without cmd it works etc. but I need this cmd start solution)


Solution

  • You could escape the & character with a caret ^:

    cmd /C start iexplore https://www.google.hu/?gfe_rd=cr^&ei=r9frVbawJZChOomkqIgH&gws_rd=ssl#q=find
    

    Or simple enclose the URL in a pair of quotes ":

    cmd /C start "" iexplore "https://www.google.hu/?gfe_rd=cr&ei=r9frVbawJZChOomkqIgH&gws_rd=ssl#q=find"
    

    Since start interprets the first quoted string as window title, I added an empty string "".