BryanC
asked on
Get the Web server machine name using JavaScript
I can get the Machine Name of my Web server using VBScript with the following.
Set WshNetwork = server.CreateObject("WScri pt.Network ")
MachinName=WshNetwork.Comp uterName
How can I get this information using JavaScript?
Set WshNetwork = server.CreateObject("WScri
MachinName=WshNetwork.Comp
How can I get this information using JavaScript?
ASKER
How can I pass it from the server to the client?
In your script code you could just write the value.
<script language="javascript" type="text/javascript">
....code....
var machineName = <%=MachinName%>
....code....
</script>
<script language="javascript" type="text/javascript">
....code....
var machineName = <%=MachinName%>
....code....
</script>
ASKER
I do not know much about JavaScript but I need to modify an existing file. It starts out with JavaScript.
<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma ','no-cach e')
Response.AddHeader('cache- control',' no-store')
<!--#INCLUDE VIRTUAL='...'-->
<!--#INCLUDE VIRTUAL='...'-->
Is there some way to just call a VB function from within JavaScript that will return the Machine Name?
<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma
Response.AddHeader('cache-
<!--#INCLUDE VIRTUAL='...'-->
<!--#INCLUDE VIRTUAL='...'-->
Is there some way to just call a VB function from within JavaScript that will return the Machine Name?
try this:
================
<script language="javascript" type="text/javascript">
var machineName ="<%=Request.ServerVariabl es("SERVER _NAME")%>" ;
</script>
================
<script language="javascript" type="text/javascript">
var machineName ="<%=Request.ServerVariabl
</script>
I suggest asking this question to be moved to the ASP section:
https://www.experts-exchange.com/Web/Web_Languages/ASP/
They will most likely be able to help you. From what I recall of those days, you can call and use any objects and/or variables across javascript and vb in the ASP-page, just as long as you realise that JavaScript is case-sensitive.
Hope it helps,
Martin
https://www.experts-exchange.com/Web/Web_Languages/ASP/
They will most likely be able to help you. From what I recall of those days, you can call and use any objects and/or variables across javascript and vb in the ASP-page, just as long as you realise that JavaScript is case-sensitive.
Hope it helps,
Martin
ASKER
The suggestion by devic returns the server name supplied in the URL. However, this is the alias name of the Web server and not the actual server name.
We have two web servers, JcoPimWeb01 and JcoPimWeb01. We have an alias defined as JcoPimIIS01 and the users reference it in there URL so that when we need to work on the production web server we simply change the IP address of the alias and the users continue to use the same URL.
MachineName = "<%=Request.ServerVariable s('"SERVER _NAME")%>" ;
Returns alias name (JcoPimIIS01).
Set WshNetwork = server.CreateObject("WScri pt.Network ")
MachinName=WshNetwork.Comp uterName
Returns actual machine name (JcoPimWeb01).
Is there a call that will return the actual machine name?
Thanks,
Bryan
We have two web servers, JcoPimWeb01 and JcoPimWeb01. We have an alias defined as JcoPimIIS01 and the users reference it in there URL so that when we need to work on the production web server we simply change the IP address of the alias and the users continue to use the same URL.
MachineName = "<%=Request.ServerVariable
Returns alias name (JcoPimIIS01).
Set WshNetwork = server.CreateObject("WScri
MachinName=WshNetwork.Comp
Returns actual machine name (JcoPimWeb01).
Is there a call that will return the actual machine name?
Thanks,
Bryan
You are actually using serverside javascript, which is causing some confusion.
The code you want is:
var WshNetwork = server.CreateObject("WScri pt.Network ");
var MachinName = WshNetwork.ComputerName;
The code you want is:
var WshNetwork = server.CreateObject("WScri
var MachinName = WshNetwork.ComputerName;
ASKER
boblah
This does not seem to work. With the following code I get the "test1" message but nothing else.
alert("test1")
var WshNetwork = server.CreateObject("WScri pt.Network ");
var MachinName = WshNetwork.ComputerName;
alert(MachinName);
alert("test2")
This does not seem to work. With the following code I get the "test1" message but nothing else.
alert("test1")
var WshNetwork = server.CreateObject("WScri
var MachinName = WshNetwork.ComputerName;
alert(MachinName);
alert("test2")
try
<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma ','no-cach e')
Response.AddHeader('cache- control',' no-store')
var WshNetwork = server.CreateObject("WScri pt.Network ");
var MachineNameServerSide = WshNetwork.ComputerName;
%>
Machine name = <%=MachineNameServerSide %>
<script LANGUAGE="JavaScript">
<!--
var MachineNameClientSide = '<%=MachineNameServerSide %>';
-->
</script>
<input type="button" onclick="alert('Machine name of the server is ' + MachineNameClientSide);" />
<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma
Response.AddHeader('cache-
var WshNetwork = server.CreateObject("WScri
var MachineNameServerSide = WshNetwork.ComputerName;
%>
Machine name = <%=MachineNameServerSide %>
<script LANGUAGE="JavaScript">
<!--
var MachineNameClientSide = '<%=MachineNameServerSide %>';
-->
</script>
<input type="button" onclick="alert('Machine name of the server is ' + MachineNameClientSide);" />
ASKER
I get the following error:
Error Type:
Microsoft JScript runtime (0x800A1391)
'server' is undefined
/web21/pfdFreePlot_LBC.asp , line 7
Error Type:
Microsoft JScript runtime (0x800A1391)
'server' is undefined
/web21/pfdFreePlot_LBC.asp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
boblah
Thank you. This works.
Thank you. This works.
var MachinName = WshNetwork.ComputerName;
this won't work though for javascript. Default browser security probably won't let you create the activex object. And, even if it did, that would get the computer name of the client, not the server.
But like i said that probably won't work becuase of default browser security.
There is no way to get the name of the webserver from the client. YOu can pass it to the client from the server, but other than that your kinda stuck