Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.write(window.location.href)

Status
Not open for further replies.

chasdrury

IS-IT--Management
Aug 8, 2001
12
0
0
GB
Hi

I have got the above (subject line) of script working and now on my page i get a full listing - ie on my page of text. Is there a way of telling the javascript to knock off the bit so I just get the words 111111.com?

Help much appreciated

Chaz
 
try

Code:
document.write(window.location.hostname)

This would write
Code:
  [URL unfurl="true"]www.11111.com[/URL]
but I do not know of a way of returning the url without the H

bhogar@acxiom.co.uk
 
may be
var str=window.location.hostname
var total=str.length-4
var result=str.substr(4,total)
document.write(result) ??
regards, vic
 
vituz, your solution does not work on all sites. if for example the entire url is: then it will remove part of the user, instead try a code that checks if or not, if it doesn't then do a for(...) loop to find the first / and then using substring to capture the rest of the url.

can post a small code later if needed My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
ok, sorry, didnt thought about it X-)
regards, vic
 
hostname = window.location.hostname;
results = temp.match(/w{3}?\.(.*)/);

/*results[0] contains the whole match, results[1] contains the first parenthesized expression(regexps rock!)*/

document.write(results[1]);
 
but they look confusing, dont they? ;-)
Code:
hostname=window.location.hostname;
[URL unfurl="true"]www=hostname.indexOf('www.');[/URL]
if ([URL unfurl="true"]www!=-1)[/URL] hostname=hostname.substring([URL unfurl="true"]www+4,hostname.length);[/URL]

document.write(hostname);
that should work, although I agree that reg exp's are more compact, this is more readable theEclipse
eclipse_web@hotmail.com
**\\||It was recently discovered that research causes cancer in rats||//**
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top