Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

window.location - How about just the domain?

Posted on 2003-11-15
11
Medium Priority
?
53,702 Views
Last Modified: 2011-08-18
window.location is for the current document URL, how about just the domain?

I am trying to set the homepage but it uses the long URL (including the querystring)


Thanks
Bill D
0
Comment
Question by:B_Dorsey
[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
  • 3
  • 2
11 Comments
 
LVL 10

Expert Comment

by:NetGroove
ID: 9757199
Hello Bill,

window.location is an object. It evaluates to a String.
But that object has several properies.
In your case you should use:  window.location.domain


Look also for: window.location.URL and window.location.href

Good luck,
NetGroove

0
 
LVL 10

Assisted Solution

by:NetGroove
NetGroove earned 200 total points
ID: 9757207
Oh, and other properties of window.loaction object are: hash and search.
Like this:
window.location.hash  // yields the #part of the url
window.location.search  // yields the ?part of the url

0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9757217
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 10

Expert Comment

by:NetGroove
ID: 9757226
Uhps! It looks like window.location.domain is not a property.
Try then:
  window.location.host

0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9757240
Try also:
  document.domain

0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9757261
0
 
LVL 15

Expert Comment

by:JakobA
ID: 9757301
Do not thrust those properties too much. Not all browsers fill them. In Opera for one you cannot really rely on anything but location.href.

So for the domain I would do a quick parse:

var temp = window.location.href.split("/");
var domain = temp[2];               // you may still need to peel of port number and such.
0
 
LVL 14

Author Comment

by:B_Dorsey
ID: 9757319
I cant get any of these to work for some reason, maybe I cant use it in the spot I want to .... see below

<script language="JavaScript">
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
      document.write("<A HREF=\"javascript:window.external.AddFavorite(window.location.href);\" ");
      document.write("onMouseOver=\"window.status=");
      document.write("'Bookmark this site'; return true;\" ");
      document.write("onMouseOut=\"window.status=");
      document.write("' '; return true;\"");
      document.write("><img src=\"/images/browser_settings/bookmark_ie.gif\" width=\"186\" border=\"0\" height=\"30\"></a>");
}
else {
      document.write("<img src=\"/images/browser_settings/bookmark_other.gif\" width=\"186\" border=\"0\" height=\"30\">");
      }
</script>

Also by chance where in this code would I put the name of the bookmark?

Thanks Guys
Bill D
0
 
LVL 14

Author Comment

by:B_Dorsey
ID: 9757320
Its in this line that Im trying to make it work

document.write("<A HREF=\"javascript:window.external.AddFavorite(window.location.href);\" ");


Bill D
0
 
LVL 15

Expert Comment

by:JakobA
ID: 9757357
try this:
document.write("<A HREF=\"#\" onclick=\"window.external.AddFavorite(window.location.href);return false\" ");
0
 
LVL 15

Accepted Solution

by:
JakobA earned 800 total points
ID: 9757369
or to set just first part (including domain)

document.write("<A HREF=\"#\" onclick=\"var x=window.location.href.split('/'); x.length=3;window.external.AddFavorite(x.join('/'));return false;\" ");
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

688 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