• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

window.location.port not working?

If I have the following in the HTML page thispage.htm
<body>
 <script language=Javascript>
 alert(window.location.hostname); //or (use .host)
 alert(window.location.port);
 </script>
</body>

and I go to http://222.222.222.222:80/thispage.htm

first alert I get is fine
222.222.222.222
second one comes up blank. Why?

Is it some sort of a firewall config.  

Can someone else share a snippet that actually gets the :80 (or any other) port number into a variable?

Thanks
0
geoenvi
Asked:
geoenvi
  • 6
  • 5
1 Solution
 
ZvonkoSystems architectCommented:
If your window.location.href does NOT contain the port, then you will not get the location.port
Have a look at the complete location.href


0
 
geoenviAuthor Commented:
I thought the location object contains what is typed in the URL addressbar of IE?  I browse to  http://222.222.222.222:80/thispage.htm and it clearly contains port number there
0
 
ZvonkoSystems architectCommented:
I just tested on my IIS. You are right, it is strange. The port was not passed neither to href nor to port!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
geoenviAuthor Commented:
My point exactly.  So.. what is the solution

:0)
0
 
ZvonkoSystems architectCommented:
Ok, I changed my IIS port from 80 to 8081 and the port was passed to href and port.
So my assumption is that  the port is normalized in any way before passed to script environment.

0
 
geoenviAuthor Commented:
meaning that any port other than 80 would be passed into the location.port?
0
 
ZvonkoSystems architectCommented:
Yeap!
0
 
ZvonkoSystems architectCommented:
Or any port other then 443 for https.
0
 
geoenviAuthor Commented:
Do you know if this is an IIS specific trait or is it IE specific or what?
0
 
geoenviAuthor Commented:
Thanks Zvonko. You have helped a lot in the recent past. You can truly wear your your expert badge of honor

:-)
0
 
ZvonkoSystems architectCommented:
Thanks :-)

This worked also for port 80 on ASP side:
<% Response.Write("Port: " & Request.ServerVariables("SERVER_PORT")) %>

And I do not know how general that port problem is.
I can imagine that the normlization is done on browser side, because there is the scripting engine environment.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now