1

I have to start many applications on the start of my day. Now I've written a .bat file to do this all automatically. The only thing that is not working is starting a chrome instance with javascript code in the .bat file.

What I want to do is to start chrome (or IE): start chrome url. But now I don't want to put there an "URL" but some JavaScript like below. If I run this in an empty addressbar in Chrome it works.

start chrome javascript:window.open('http://websiteurl.com/').ready(Button.clickIt());

If I do this using the CMD (or .bat file) then it doesn't work. It opens an empty chrome instance.

Is there any way to achieve this?

Few things I found out:

  • When copy/pasting javascript:window.open('http://websiteurl.com/').ready(Button.clickIt()); in Chrome, it removes the javascript: part. Maybe this happens also when opening it using CMD?
  • Internet Explorer gives much more problems. It will prompt you to download files sometimes. No clue why.
JeroenE
  • 603
  • 7
  • 22

2 Answers2

0

I don't think this is going to be possible. According to this SO question (and this one), Chrome will automatically strip javascript: for "security" reasons. This is basically what you posited in your original question.

You could probably accomplish this using VBscript and WinHttpRequest.

  • I just use a bat file as I know how to use it. I'll look for the VBScript tomorrow. Thanks for the suggestion! – JeroenE Sep 19 '18 at 17:20
  • I think you're right that it's not possible. So I did stop researching for it. Thanks for your response. I've accepted this answer because of your first line. "I don't think this is going to be possible". Browsers are now a days removing the "javascript:" part. It only works if you put it in by hand I guess. – JeroenE Sep 21 '18 at 08:24
-1

have you tried start chrome http://websiteurl.com/? credit to writing a batch file that opens a chrome URL

Tom
  • 7
  • 5
  • Yes, but that's not what I need. I want to run `javascript:window...` instead of an URL to be able to click on a button on that page I'm opening. If you open the URL like you described (and I did in my post) then you cannot do anything on the page anymore using the cmd/bat file – JeroenE Sep 19 '18 at 13:38