Solved

window.location.port not working?

Posted on 2004-09-07
11
288 Views
Last Modified: 2012-05-05
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
Comment
Question by:geoenvi
  • 6
  • 5
11 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 12001624
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
 

Author Comment

by:geoenvi
ID: 12001642
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 12001651
I just tested on my IIS. You are right, it is strange. The port was not passed neither to href nor to port!
0
 

Author Comment

by:geoenvi
ID: 12001659
My point exactly.  So.. what is the solution

:0)
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 12001678
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:geoenvi
ID: 12001687
meaning that any port other than 80 would be passed into the location.port?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12001690
Yeap!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12001698
Or any port other then 443 for https.
0
 

Author Comment

by:geoenvi
ID: 12001712
Do you know if this is an IIS specific trait or is it IE specific or what?
0
 

Author Comment

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

:-)
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12001747
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now