Link to home
Start Free TrialLog in
Avatar of geoenvi
geoenvi

asked on

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
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

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


Avatar of geoenvi
geoenvi

ASKER

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
I just tested on my IIS. You are right, it is strange. The port was not passed neither to href nor to port!
Avatar of geoenvi

ASKER

My point exactly.  So.. what is the solution

:0)
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geoenvi

ASKER

meaning that any port other than 80 would be passed into the location.port?
Yeap!
Or any port other then 443 for https.
Avatar of geoenvi

ASKER

Do you know if this is an IIS specific trait or is it IE specific or what?
Avatar of geoenvi

ASKER

Thanks Zvonko. You have helped a lot in the recent past. You can truly wear your your expert badge of honor

:-)
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.