I have an intranet app that needs to know where to print some labels. We have multiple workstations setup. I need a way to retrieve the host name of the client so that when they print something it es out of the correct printer. Right now I have this being set at login but was curious if I could actually pull the host name on the client side, then on the server side i could easily parse the hostname to set the printer. The solves the problem of a user being logged into two workstations at once. Granted it shouldn't happen but users will be users.
The application is printing labels to a zebra printer so the printing occurs on the server but the print job is sent to the label printer that is next to the workstation being used.
TIA!
I have an intranet app that needs to know where to print some labels. We have multiple workstations setup. I need a way to retrieve the host name of the client so that when they print something it es out of the correct printer. Right now I have this being set at login but was curious if I could actually pull the host name on the client side, then on the server side i could easily parse the hostname to set the printer. The solves the problem of a user being logged into two workstations at once. Granted it shouldn't happen but users will be users.
The application is printing labels to a zebra printer so the printing occurs on the server but the print job is sent to the label printer that is next to the workstation being used.
TIA!
Share Improve this question asked Jun 15, 2011 at 14:40 OminusOminus 5,7318 gold badges43 silver badges45 bronze badges 1- If it's an intranet, is IE required, or can you use whatever? – Robert Commented Jun 15, 2011 at 14:49
2 Answers
Reset to default 2Since the printing is done server-side, why do you need a JavaScript solution?
What you need is to check whatever is the equivalent to the REMOTE_HOST and/or REMOTE_ADDR CGI variables on your server's implementation.
Edit: in case you can't change the printing code, reverting to a separate script called through AJAX, as Andrew suggested, may be a way of getting what you want. But it looks like a very circuitous way of doing it.
There isn't any reliable way to do what you're asking without using an external script and requesting it via Ajax.
See also: Can I perform a DNS lookup (hostname to IP address) using client-side Javascript?
Edit: note, if you can it would be better (less HTTP requests) and easier to just include the host name in a dynamically generated <script>
tag on the server-side before the page is loaded, that way the data is already there when you need it.