?
Solved

window.location.port not working?

Posted on 2004-09-07
11
Medium Priority
?
297 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

:0)
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

777 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