How could I write a Windows batch script that could allow me to open an URL, with a browser—Firefox or Chrome—from a txt file containing all the URIs?

The point is: I would like the script to open the next URL only once I have closed the tab from the last URL.

I have around 600+ URIs to screen by eye, and I would like to ease the process.

  • 1
    You cannot do this unless the browser can be closed entirely. Can you also tell us what you have tried so far? This is not a "please write me a script" kind of site. But we'll gladly help you with your script and tell you why it doesn't work. – LPChip Apr 4 '15 at 15:54
  • I agree on that, I couldn't even close a tab. I have been doing this task a few times in the last monthes but my file is gettng bigger and bigger so I wrote a little sh script to open URL automatically. But because of the performance I had to cut my input txt file into multiple ones (20 URIs max). Firefox couldn't open more at the same time without freezing. That's why I was looking for more elegant solution + I also have to do this on Win Ps : I've been using StackOverflow for years, sorry if my question sounds newbie. I'm looking for some ideas or function name that could do the trick :) – corentino Apr 4 '15 at 16:35
  • You could wait until Firefox is closed and then run it again with the next URL. This way you only need to press Alt+F4 (or equivalent) to go to the next site. – Kos Apr 4 '15 at 21:49

The same solution in PowerShell:

$urllist = Get-Content C:\temp\listeurl.txt
foreach($url in $urllist)
    $proc = start-process "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -argumentlist $url -PassThru
    start-sleep -seconds 10
    stop-process $proc -force -erroraction silentlycontinue
| improve this answer | |

If you want to close the window manually, and if you use a browser that allows popups from JavaScript, then you could use a JavaScript solution.

Limited by same-domain security policies, this needs an ugly timer to see if the child window is meanwhile closed.

Also note that opening the first window will be fine, as that is (eventually) triggered by you clicking the "Start" button. However, subsequent windows opened by JavaScript should be blocked by sane browsers, so look for that "popup blocked" warning. Both Chrome and Firefox will do fine; they will first block the second URL which also makes the script fail. Simply accept the popups and then refresh the JavaScript page:

<!DOCTYPE html>
  <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <textarea id="urls"></textarea>
  <button id="start">Start</button>
function openUrl(urls){
  if(urls.length > 0){
    var url = urls.shift().trim();
    var w = window.open(url);
    var timer = setInterval(function(){   
    }, 500);
    alert("That's all");

$("#start").on("click", function(){

Live example: http://jsbin.com/loweyocofu/1/

| improve this answer | |

This is not exactly script I wanted, but it does the job (on Linux, in Python):

import subprocess as sp
import webbrowser
import time

f = open('listeurl.txt','r')
urls = f.readlines()
for url in urls:
    child = sp.Popen(["firefox", url ])

It creates a Firefox window, open the URL received from txt and waits for 10 seconds before closing itself and opening the next URL.

I don't know why, it always keeps the first URL opened in a tab.

If anyone want to improve, you're welcome :)

| improve this answer | |

set /a a=0

goto :1


set /a a=%a%+1

for /f "tokens=%a% delims=%1" %%G in ('type YourTextFile.txt') do (

start %%G


goto :1

| improve this answer | |
  • Please read the question again carefully. Your answer does not answer the original question. "The point is: I would like the script to open the next URL only once I have closed the tab from the last URL." – DavidPostill Apr 27 '16 at 10:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.