10

At the command line I can load websites like this:

firefox.exe google.com

However, what I am trying to load is the following:

javascript:q=document.getSelection();d='U';c=document.characterSet;if(c=='Shift_JIS')d='S';if(c=='EUC-JP')d='D';if(!q){void(q=prompt('Enter%20text%20to%20search%20using%20WWWJDIC%20(Japanese).',''))};if(q)location.href='http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1M'+d+'J'+q

This will load if I paste it in the address bar of firefox, but it will not load if I specify it as an argument from the command line. How can I make it load from the command line?

5
  • At least in windows, the problem is made more complicated by the fact that both the 'run' command and shortcuts limit the number of characters allowed to less than the code you want to run takes.
    – Emil
    Jun 27, 2010 at 13:27
  • As the answer hasn't been accepted yet, did my solution work? Jul 16, 2010 at 0:39
  • It didn't work.
    – Phenom
    Jul 16, 2010 at 13:18
  • It works for me, either the mistake is with encapsulation or you're trying to do too much. Which brings me to the question: What are you trying to do? Aug 10, 2010 at 15:20
  • If it works for you then you should know what it does.
    – Phenom
    Aug 10, 2010 at 18:43

2 Answers 2

8

Encapsulating it with double quotes works for me:

firefox "javascript:alert('Hello World')"
3
  • Tried the above on my browser from the Linux Bash prompt and it brought up a page with the "javascript:alert('Hello World')" text in the address bar, but did not execute it. My User Agent is: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:35.0) Gecko/20100101 Firefox/35.0. So how do we get it to execute? I'm running Firefox from the command line so Firefox should just execute it, right?
    – bgoodr
    Feb 7, 2015 at 17:51
  • 2
    @bgoodr Add -new-window. It will launch a new window and execute the JS. Only problem is that JS with window object will not execute as window object is null when the window is launching.
    – ADTC
    Jul 7, 2015 at 7:30
  • Though theoretically it should be "--new-window" the parameter provided by @ADTC works on palemoon. However, it doesn't on the modern Firefox 112 Apr 26, 2023 at 16:44
-3

From HowTo: Run Firefox From The Command Line:

You can use command line as follows with special arguments to start Mozilla Firefox.

To open the browser, enter:

firefox

OR

/usr/bin/firefox

Firefox Open URL

To open URL in a new tab, enter:

/usr/bin/firefox -new-window http://www.cyberciti.biz/

To open URL in a new window, enter:

/usr/bin/firefox www.cyberciti.biz

Firefox Search option

You can search words (term) with your default search engine, enter:

/usr/bin/firefox -search "term"
/usr/bin/firefox -search "linux add user to group"

Open Firefox Options / Preferences

To open Firefox options/preferences window, enter:

/usr/bin/firefox -preferences

Set Firefox As Default Browser

To set the Firefox app as the default browser, enter:

/usr/bin/firefox -setDefaultBrowser
1
  • 4
    Next time, please don't just copy and paste content from other sites. Link to them, and quote everything you didn't write yourself. Thank you. Plus, you're not really answering the question – this is not what the OP wanted.
    – slhck
    Jul 16, 2012 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .