How do I run a javascript within html from the command line and include arguments?

Rory A Campbell

I have an html javascript program that opens 4 browser windows. I want to run this from the command line and include arguments that specify the URLs to be opened. Is this possible?

The current code looks like this:

<html>
<script>
function openWindows(url1, url2, url3, url4) {
  window1=window.open(url1,'','width=725,height=480');
  window1.moveTo(0, 0);
  window2=window.open(url2,'','width=725,height=480');
  window2.moveTo(0, 480);
  window3=window.open(url3,'','width=725,height=480');
  window3.moveTo(725, 0);
  window4=window.open(url3,'','width=725,height=480');
  window4.moveTo(725, 480);
};

</script>
<body onload="openWindows()">
</html>

How can I modify it so that it can be run with URL arguments form the command line? Im using a macbook. Thanks

JosephGarrone

It is not possible (At least in practicality) to interface from your MacBook Terminal/Command Prompt window and a Javascript webpage.

I would recommend that you look at other methods to try and accomplish this, such as an Apple Script which can open up your browser and navigate to 4 separate URLs.

However, if you must do it in Javascript, and you must be able to send these commands from your terminal, I would look into having your terminal accept 4 URL inputs, and then write the URLs to a Javascript file.

>> Input URL 1: ...
>> Input URL 2: ...
>> Input URL 3: ...
>> Input URL 4: ...
>> Now that you have the 4 urls, write to a Javascript file in the format:
var url1 = inputfromurl1;
var url2 = inputformurl2; //And so on for 4 urls
function openWindows()
{
    window1=window.open(url1,'','width=725,height=480');
    window1.moveTo(0, 0);
    window2=window.open(url2,'','width=725,height=480');
    window2.moveTo(0, 480);
    window3=window.open(url3,'','width=725,height=480');
    window3.moveTo(725, 0);
    window4=window.open(url3,'','width=725,height=480');
    window4.moveTo(725, 480);
};

Then I would save that file as browserscript.js or something similar. I would then have a HTML file like such:

<html>
<head>
    <script src="browserscript.js"/>
</head>
<body onload="openWindows();">
</body>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I call python program (which has command line arguments) from PHP or Javascript?

From Dev

How do I provide arguments to a command run from gksudo?

From Dev

How do I read arguments from the command line with an MPI program?

From Dev

How do I run a gui app from the command line?

From Dev

How do I run a gui app from the command line?

From Dev

How do I run this script with sudo from the command-line?

From Dev

How do I run .c file from the command line

From Dev

How can I run a command line command from within a ruby file?

From Dev

How can I run an application with command line arguments in Mac OS

From Dev

How to run the job within springbatchadmin.war from the command line?

From Dev

How do I fix output from command-line arguments to printing out the correct integers?

From Java

How do I parse command line arguments in Java?

From Java

How do I parse command line arguments in Bash?

From Dev

How do I access command line arguments in SICStus Prolog?

From Dev

How do I ignore escape characters in command line arguments?

From Dev

How do I pass command line arguments to stack exec

From Dev

How do I parse command line arguments in Dart?

From Dev

How do I find out command line arguments of a running program?

From Dev

How do I get raw VBScript command line arguments?

From Dev

How do I check the second element of the command line arguments?

From Dev

How do I run xctest from the command-line with Xcode 5?

From Dev

How do I run a Cocoa app after building it from the command line with xcodebuild?

From Dev

How do I run dcm4che tools from command line after compilation?

From Dev

How do I run a Metro-Application from the command-line in Windows 8?

From Dev

How do I run an argument from a program in the windows command-line?

From Dev

How do I run a LibreOffice macro from the command line without the GUI?

From Dev

How do I run IIS Express from the command line with "Enabled 32 bit applications" enabled?

From Dev

How do I run a command in bash from zsh (or some other shell) in one line?

From Dev

How do I get the command-line for an Eclipse run configuration?

Related Related

  1. 1

    How do I call python program (which has command line arguments) from PHP or Javascript?

  2. 2

    How do I provide arguments to a command run from gksudo?

  3. 3

    How do I read arguments from the command line with an MPI program?

  4. 4

    How do I run a gui app from the command line?

  5. 5

    How do I run a gui app from the command line?

  6. 6

    How do I run this script with sudo from the command-line?

  7. 7

    How do I run .c file from the command line

  8. 8

    How can I run a command line command from within a ruby file?

  9. 9

    How can I run an application with command line arguments in Mac OS

  10. 10

    How to run the job within springbatchadmin.war from the command line?

  11. 11

    How do I fix output from command-line arguments to printing out the correct integers?

  12. 12

    How do I parse command line arguments in Java?

  13. 13

    How do I parse command line arguments in Bash?

  14. 14

    How do I access command line arguments in SICStus Prolog?

  15. 15

    How do I ignore escape characters in command line arguments?

  16. 16

    How do I pass command line arguments to stack exec

  17. 17

    How do I parse command line arguments in Dart?

  18. 18

    How do I find out command line arguments of a running program?

  19. 19

    How do I get raw VBScript command line arguments?

  20. 20

    How do I check the second element of the command line arguments?

  21. 21

    How do I run xctest from the command-line with Xcode 5?

  22. 22

    How do I run a Cocoa app after building it from the command line with xcodebuild?

  23. 23

    How do I run dcm4che tools from command line after compilation?

  24. 24

    How do I run a Metro-Application from the command-line in Windows 8?

  25. 25

    How do I run an argument from a program in the windows command-line?

  26. 26

    How do I run a LibreOffice macro from the command line without the GUI?

  27. 27

    How do I run IIS Express from the command line with "Enabled 32 bit applications" enabled?

  28. 28

    How do I run a command in bash from zsh (or some other shell) in one line?

  29. 29

    How do I get the command-line for an Eclipse run configuration?

HotTag

Archive