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
Solved

window.location - How about just the domain?

Posted on 2003-11-15
11
53,673 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
  • 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 50 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
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.

 
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 200 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

790 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