Solved

window.location.port not working?

Posted on 2004-09-07
11
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

691 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