Solved

window.location - How about just the domain?

Posted on 2003-11-15
11
53,680 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
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!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery Syntax... 4 50
How to make google charts responsive 4 49
Table style position to the left 8 25
Prevent certain words from being typed in a form 6 28
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

756 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