Solved

window.location - How about just the domain?

Posted on 2003-11-15
11
53,662 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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'…
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…

762 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

16 Experts available now in Live!

Get 1:1 Help Now