Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to run a JavaScript command from the command line, in Windows 7, using a batch file. The batch file is run as an administrator.

I am trying to open an Internet Explorer 8 window, as part of a longer routine. If I simply call IEXPLORE.EXE in a batch file without using JavaScript, Internet Explorer 8 opens okay:

"C:\Program Files\Internet Explorer\IEXPLORE.EXE"

If I call a URL as well, the specified page opens:

"C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://www.google.com

However if I try to use JavaScript in the batch file, to control the size and location of the Internet Explorer 8 window, an Internet Explorer window starts to open but before it finishes opening the routine aborts with the error message 'Unable to download. Unspecified error.':

"C:\Program Files\Internet Explorer\IEXPLORE.EXE" javascript:window.open("http://www.google.com","newwin","left=10,top=10,width=520,height=250");

Active scripting is enabled in Internet Explorer's options.

The fault does not appear to be caused by the DOCOBJ.DLL file which comes with older versions of Microsoft Office. Although I did install Office on my system, which is running Internet Explorer 8, so an old version of DOCOBJ.dll was registered, I have since unregistered it and re-registered IEPROXY.DLL but the fault with window.open() persists -

"C:\Program Files (x86)\Internet Explorer\ieproxy.dll"

Can anyone suggest what I'm overlooking?

share|improve this question
I don't think it's possible to pass javascript to the browser in this way. You could probably make a page for it to open which could spawn this window and then close itself. Perhaps put the entire string you wish to pass in a single qoutes? –  Melikoth Dec 5 '11 at 12:58
Thank you for this useful suggestion Melikoth, which hadn't occured to me. I will try it, as it sounds like a viable work-around. I'll post back here with my results. –  Ed999 Dec 5 '11 at 18:02
Your suggestion worked. –  Ed999 Dec 26 '11 at 12:09

3 Answers 3

Thank you, Melikoth. You put me on the right track. A lot of trial and error has produced this solution, in Windows 7.

This uses caret escaping.

Replace all instances of # with <

Contents of OPEN.BAT -


    echo ^#html^> >> %temp%\temp.htm

    echo ^#head^> >> %temp%\temp.htm

    echo ^#title^>^#/title^> >> %temp%\temp.htm

    echo ^#script language='JavaScript' type='text/javascript'^>function
    run(){window.open('','_self');var t = openWin(newWin())}function
    newWin(){window.open('http://www.bbc.co.uk/iplayer/console/b007jqsz','','left=10,top=10,width=400,height=600,toolbar=0,location=0,directories=0,status=0,scrollbars=0');window.close()}^#/script^> >> temp%\temp.htm

    echo ^#/head^> >> %temp%\temp.htm

    echo ^#body onload='run()'^> ^#/body^> >> %temp%\temp.htm

    echo ^#/html^> >> %temp%\temp.htm

    "C:\Program Files\Internet Explorer\IEXPLORE.EXE" %temp%\temp.htm

share|improve this answer
Glad you were able to get a workable solution! –  Melikoth Dec 27 '11 at 16:30

javascript: is not a standard URL scheme (like http, https, ftp etc.). Rather, whenever a browser encounters it during a click operation, it treats the following statement as a JavaScript statement and executes it. You therefore cannot activate if from the outside.

share|improve this answer
In fact you CAN activate javascript from a batch file. I used to do it all the time in Windows 98. I was actually bemoaning the fact that my standard Windows 98 batch file solution isn't working in Windows 7, in this one instance, even though many other command line tricks which I've been using ever since Win98 still run fine. –  Ed999 Dec 5 '11 at 18:10
Yes, I've also seen articles on the web dating from around 2002/2003 that describe this trick. Things have obviously changed since then. –  Todd Owen Oct 9 '13 at 1:21

Here is my revised .BAT batch file OPEN.BAT with a timing function added to delay closure of the opener window until the child window has opened fully.

Replace all instances of # with <

echo ^#html^> >> %temp%\temp.htm

echo ^#head^> >> %temp%\temp.htm

echo ^#title^>^#/title^> >> %temp%\temp.htm

echo ^#script language='JavaScript' type='text/javascript'^>function run(){window.open('','_self');var t = openWin(newWin())}function newWin(){window.open('http://www.bbc.co.uk','','width=382,height=666,left=10,top=10,toolbar=0,location=0,status=0,scrollbars=0');setTimeout('window.close()',5000)}^#/script^> >> %temp%\temp.htm

echo ^#/head^> >> %temp%\temp.htm

echo ^#body onload="run()"^> ^#/body^> >> %temp%\temp.htm

echo ^#/html^> >> %temp%\temp.htm

"C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE" %temp%\temp.htm

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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