Solved

window.location - How about just the domain?

Posted on 2003-11-15
11
53,669 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
is this a cms? 8 58
would you please explain me the conditional part ? 4 21
Web forms being filled out by bots 4 31
Help with removing item from Session Array 3 21
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

815 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

9 Experts available now in Live!

Get 1:1 Help Now