36

I have a list of URLs in a text file, for example,

http://url1
http://url2
http://url3

I wonder how to open them each in one tab in Firefox (or SeaMonkey), without the hassle of creating a new tab, copying into address bar and hitting return for each URL?

My OS is Ubuntu 10.10. Both command line and GUI solutions are welcome.

0

6 Answers 6

36

You can save the following to a HTML file:

<!doctype html>
<html>
<head>
<title>Open Windows</title>
<script>
function openWindow(){
    var x = document.getElementById('a').value.split('\n');
    for (var i = 0; i < x.length; i++)
        if (x[i].indexOf('.') > 0)
            if (x[i].indexOf('://') < 0)
                window.open('http://'+x[i]);
            else
                window.open(x[i]);
}
</script>
<style>
html, body
{
    height : 99%;
    width  : 99%;
}

textarea
{
    height : 80%;
    width  : 90%;
}
</style>
</head>
<body>
<textarea id="a"></textarea>
<br>
<input type="button" value="Open Windows" onClick="openWindow()">
<input type="button" value="Clear" onClick="document.getElementById('a').value=''">
</body>
</html>

Now load the file in Firefox, copy the list of URLs in the textarea and click Open Windows.

9
  • 1
    Hah... I haven't thought 'bout that one! I usually do it with firefox `cat file.txt` (as WakiMiko wrote). Anyway using your way will work on all OS. :D
    – tftd
    Commented Feb 2, 2012 at 16:39
  • 1
    Now this is what I call "for the win." +1 for platform independence. Would definitely accept this answer. Supported: SeaMonkey, FireFox, IE, Chrome, Safari, etc...Ubuntu, Windows, Mac, etc.
    – Matt Borja
    Commented Jun 6, 2012 at 22:39
  • Technically chrome blocking as pop-ups. But since I need source and I'm running fiddler, you made my day. Thanks a done.
    – Jones
    Commented Apr 8, 2013 at 15:12
  • This is perfect. Is there anyway to add a slight delay, lets say 5 seconds between opening each tab? Commented Nov 30, 2016 at 17:16
  • 1
    Made a functional and modernized version here -> jsfiddle.net/L06mkcvd
    – Erlend
    Commented Aug 19, 2021 at 22:11
35

A simple

firefox $(cat file.txt)

should suffice. It will pass each link as an argument to the firefox command, as long as every link is separated by whitespace.

4
  • 1
    +1. Thanks! That works! I wonder if you happen to know how to do that in SeaMonkey? I tried seamonkey $(cat urls), but only the url in the first line is opened.
    – Tim
    Commented Feb 2, 2012 at 17:03
  • 1
    if you're doing this over SSH to something running Xorg, you need to set the display to open firefox window in: env DISPLAY=:0 firefox $(cat file.txt)
    – zfogg
    Commented May 31, 2020 at 21:17
  • cat is not needed, firefox $(< example-domains.txt) is more streamlined — see stackoverflow.com/questions/11710552/useless-use-of-cat and unix.meta.stackexchange.com/questions/1261/…
    – user198350
    Commented Jun 16, 2023 at 8:35
  • If the --new-tab flag is added — firefox --new-tab $(< example-domains.txt) — Firefox only appears to open the first tab in the current window. See my answer for a potential solution (but works on my machine).
    – user198350
    Commented Jun 16, 2023 at 8:38
11

On windows you can create a batch file (named say, multiurl.bat):

@echo off    
for /F "eol=c tokens=1" %%i in (%1) do "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" %%i

and then run multiurl.bat urls.txt from the command line and it will load the URLS in new tabs if FireFox is already open, or it will run it and then load the URLS.

7
  • You aren't required to create a .bat file to use the for command. Commented Feb 2, 2012 at 16:25
  • 2
    This is not relevant - the users asks for a solution that will work on Linux machines!
    – tftd
    Commented Feb 2, 2012 at 16:37
  • 1
    @TheDevil Come on, this answer took longer than three minutes to test and type. I suggest tfitzgerald keeps this answer up, there might be others interested. I sure won't delete my answer for OS X.
    – Daniel Beck
    Commented Feb 2, 2012 at 17:20
  • @TheDevil Yes, he edited his question as I was writing my answer. Commented Feb 3, 2012 at 1:47
  • 1
    @OliverSalzburg That is correct. But I don't think I said you are required to...but why would you want to type that whole line each time you wanted to do this? That is what scripts are for! Commented Feb 3, 2012 at 1:48
8

On Mac OS X, save the following script as openurls.sh, run chmod +x openurls.sh in Terminal, and then type ./openurls.sh from the same directory.

#!/usr/bin/env bash

while read line ; do
    open -a Firefox "$line"
done < "/path/to/file-with-urls.txt"
5
  • +1. Thanks! Do you also know how to do that for SeaMonkey instead of Firefox?
    – Tim
    Commented Feb 2, 2012 at 16:12
  • @Tim I don't have SeaMonkey to test it. Also, I'm afraid this script opens windows instead of tabs, sorry about that.
    – Daniel Beck
    Commented Feb 2, 2012 at 16:16
  • 1
    This can easily be fixed with changing some settings in Firefox. Go to Edit->Preferences->Tabs and select "Open new window in new tab instead" :)
    – tftd
    Commented Feb 2, 2012 at 16:41
  • @TheDevil Thanks! I guess it's obvious I only use FF for answering questions on SU.
    – Daniel Beck
    Commented Feb 2, 2012 at 16:42
  • Is there a way to specify the Firefox profile? Commented Nov 30, 2016 at 16:46
2

Open your text file in firefox as

file:///C:/URLTextFile.txt
  1. Select the whole link
  2. Right click on it
  3. Click on "Open Link in new tab"
1
  • 1
    Only opens one (ex. the first url from many selected)
    – Xen2050
    Commented May 17, 2016 at 20:29
0

To expand on an existing Linux answer, personally I strongly prefer opening all pages in the same (existing, open) browser window. Unfortunately Firefox (command-line flags) appears not to accept all the input at once and I had to implement delay (sleep) between actions with xargs (source):

<example-domains.txt xargs -I "%" sh -c '{ firefox --new-tab "%"; sleep 0.25; }'

You may be able to use a significantly shorter delay than 0.25 seconds. You can try out the method with a file containing (about the reserved domains):

https://example.com/
https://example.net/
https://example.org/
https://example.edu/
1
  • xargs 4.9.0, Mozilla Firefox 114.0 (documenting if the method turns out to be not entirely universal and compatible)
    – user198350
    Commented Jun 16, 2023 at 8:30

You must log in to answer this question.

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