1

I am trying to get client computer name in JavaScript but I am still unable to find that. Here is my JavaScript functions which I tried.

<script language="javascript" type="text/javascript">
        function GetComputerName() {
            try {
                var network = new ActiveXObject('WScript.Network');
                alert(network.computerName);
            }
            catch (e) {
                alert('a');
            }
        }
    </script>

This Function didn't return computer name even i IE.

and second function also returned nothing.

   <script type="application/javascript">
        function getip(json) {
            alert(json.ip); // alerts the ip address
        }
</script>

<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
BenMorel
  • 34,448
  • 50
  • 182
  • 322
user2024024
  • 211
  • 1
  • 4
  • 12
  • 2
    which browser are you using ? i believe Wscript works fine only on IE.. and it have certain restriction – Karthikeyan Arumugam Jan 30 '13 at 05:43
  • remote servers should never access to computer name due to security reason – zb' Jan 30 '13 at 05:45
  • Actualy I have to get Computer name in Chrome not in IE.Is there any way to get in Chrome – user2024024 Jan 30 '13 at 05:45
  • So What is the solution for my requirement – user2024024 Jan 30 '13 at 05:48
  • @user2024024 welcome to non windows-only world! browsers like chrome are crossplatform, so they trying to support only crossplatform features. my computer have hostname, but have no Computer name, and I not like if hostname will be shown to any server on network – zb' Jan 30 '13 at 05:48
  • You may want to review why you need to do such a thing, and if any work around can be done to meet the biz requirement. Using JS is not possible as it's running in 'sandbox' in browser, you may go with rich client stuff like Flex/SilverLight/JavaFX to achieve the goal – Simon Wang Jan 30 '13 at 05:49
  • Your solution - decline task – zb' Jan 30 '13 at 05:49
  • @Simon Wang Actualy i want to implement some security credentials on my web page like i want to open the web page on allowed computername name or any other client hardware information which i get and store in DB and then manage the clients to open the web page.if any other way for such type of security then tell me – user2024024 Jan 30 '13 at 05:54
  • 2
    Hmm... you've asked this [same question](http://stackoverflow.com/questions/14579752/javascript-is-not-giving-the-computer-name#comment20348489_14579752) just 20 hours ago, as a different user though. – Teemu Jan 30 '13 at 06:21
  • if you plan to collect hardware information then rich client can't help here either, you can go with code ActiveX control for IE with C++ which means your site is a IE only site, or code a client application make you stuff become C/S but not B/S – Simon Wang Jan 30 '13 at 06:26
  • I just Want to ask then Why the Above javascript functions didn't respond of computer name of client – user2024024 Jan 30 '13 at 07:23
  • @user2024024 Are you reading these comments at all? One more time, your code does not work in Chrome or other browsers, but IE. Those browsers simply don't have a function called `ActiveXObject`. When running in IE, it works only if user has "Security options" correctly (=== dangerously) set, which usually are not. – Teemu Jan 30 '13 at 12:57

0 Answers0