/    Sign up×
Community /Pin to ProfileBookmark

Passing parameters to script

I have a stand-along *.js script on the client-side called from an HTML page that I use to install printers. Since I have over 200 printers on site, I rather not write a script for each printer, therefore, does anyone know of a way to pass parameters (server name, printer name, boolean value for ‘default printer’) to this stand-along script?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 10.2005 — I'm no biggie on PHP but:

instead of using a JS file, you could use a PHP file and write-out whatever you want.

You'd have to write-out in text/javascript format though.

I doubt that that would even be necessary, why would a client-side statement need to send a parameter to a client-side script? ?

All ya gotta do is make the external JS file "see" a varible defined inside of the internal JavaScript.
Copy linkTweet thisAlerts:
@wmac222authorMay 10.2005 — Perhaps if I show a copy of my code, my problem will be better understood..

[U]printer1.js[/U]

var WshNetwork = WScript.CreateObject("WScript.Network");

WshNetwork.AddWindowsPrinterConnection("[B][ServerName][/B][B][PrinterName][/B]");

WshNetwork.SetDefaultPrinter("[B][ServerName][/B][B][PrinterName][/B]");

WScript.echo("Printer installed successfully.");

++++++++++++++++++++++++++++++++++++

[U]InstallPrinter.asp[/U]

<%

Option Explicit

Dim strPrinterName, strPrinter, strServer

Dim intA, intDF, intL

Dim objNetwork, strPrinterPath, WScript

Dim objFile, strFileName, strFilePath

On Error Resume Next

strPrinterName = Request.QueryString("PrinterName")

intDF = Request.QueryString("DefaultPrinter")

intL = Len(strPrinterName)

intA = InStr(strPrinterName, "|")

strPrinter = Left(strPrinterName, intA - 1)

strServer = Right(strPrinterName, intL - intA)

%>

<html>

<head>

<title>Install Printers Test</title>

</head>

<body>

Please confirm installation of the following printer <% Response.Write strPrinter %>

<a target="_blank" href="file:///C:/Install/JavaScripts/printer1.js">

<img border="0" id="img1" src="images/Buttons/InstallOK1.gif" height="30" width="150" alt="Install Printer">

</a>

</body>

</html>

++++++++++++++++++++++++++++++++++

Since I control over 200 printers, I do not want to write 200+ scripts, I would rather use a generic script and pass in the parameters (ServerName, PrinterName).
Copy linkTweet thisAlerts:
@UltimaterMay 10.2005 — <i>
</i>var WshNetwork = WScript.CreateObject("WScript.Network");

WshNetwork.AddWindowsPrinterConnection("\\[ServerName]\[PrinterName]");
WshNetwork.SetDefaultPrinter("\\[ServerName]\[PrinterName]");

WScript.echo("Printer installed successfully.");

I see, so your JS file is run by itself w/o being nested inside of HTML.

Why cannot you use a for loop inside of the JS file and install all the printers at once?

But if you only want one printer to be installed per user and you want to make it easy on your gallery, you should change the JS file to a PHP file becuase a PHP file can accept a query string and then write-out the desired JS file.
Copy linkTweet thisAlerts:
@wmac222authorMay 11.2005 — I am only installing one printer at a time, depending on which printer the user selects via a web page sitting on a separate web server. Have never used PHP, can you have a client-side PHP file and if so, can you send it a query from the server-side.
Copy linkTweet thisAlerts:
@UltimaterMay 11.2005 — PHP files need to be run on the server because PHP is a server-side language.

It is possible to execute a server-side program directly on a client's computer but through some kinda MS-Dos or command line if the user's computer supports it.

(this is not an option)

However, if the PHP file is located on the server, when run, it can dispatch anything it wants to the client. If it wants to send something that will be treated like a JS file then fine, it will be treated like a JS file but end in the PHP extension.

If the PHP wants to be treated like an image, fine then it will be treated like an image:

<img src="[color=royalblue]h[b][/b]ttp://www.webdeveloper.com/forum/image.[color=green]php[/color]?u=30185&dateline=1109700903[/color]">
×

Success!

Help @wmac222 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...