1

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 comes 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!

Ominus
  • 4,571
  • 6
  • 33
  • 43

2 Answers2

2

Since 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.

Zecc
  • 4,008
  • 16
  • 17
1

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.

Community
  • 1
  • 1
Andrew Curioso
  • 2,126
  • 13
  • 24
  • So I could put a little python script on their machine that would return the hostname but how would i call it from javascript? I didn't realize i could do that. – Ominus Jun 15 '11 at 14:51
  • Calling the script from Javascript is reffered to as Ajax (Asynchronous Javascript and XML - ignore the XML part, it can be other formats too). You can do it a couple ways: make the script on your server return the client information via XML or Json or you could even make the server-side script print out Javascript and include it in your page as a `script` tag: `var client_hostname=...` – Andrew Curioso Jun 15 '11 at 14:57
  • @Andrew Except the script is supposed to run on the *client*, not on the *server*. Unless you make every client into their own server. – Zecc Jun 15 '11 at 15:32
  • @Zecc See the question I linked to. The general consensus there is that it can't be done with Javascript. Now if you made an Adobe Flash app or a custom Firefox extension, that is a different story. – Andrew Curioso Jun 15 '11 at 15:39
  • I marked as answered to quickly as others have pointed out i needed it on the client side. I did see your answer further in the thread and will check it out. – Ominus Jun 15 '11 at 16:17
  • @Ominus Fair enough. I should kept my mouth shut when I discovered a client side solution ;) I may write a blog post on it and include a compiled SWF and JS interface so you people don't need to learn Flex. – Andrew Curioso Jun 15 '11 at 16:26
  • I deleted my other answer because after a good chunk of research I found out that getting the host client-side with Flash can only be done in Adobe Air which doesn't run in a browser or solve your problem. So it's back to square one... I don't think it is possible to do 100% client-side. – Andrew Curioso Jun 15 '11 at 17:40