Byte saving, string manipulation

I'm 65 bytes off of the 508 byte limit for a bookmarklet to work in IE.  I'm looking to extract the TLD of the current page (whatever.com, whatever.org, ...).  I currently have:

var r="://([^/]+)",l=document.location.href.match(r)[1].split(".");l=l[l.length-2]+"."+l[l.length-1];

This is one of the bloated parts of my script. Can anyone save me a few bytes?
LVL 18
arantiusAsked:
Who is Participating?
 
GwynforWebCommented:
in which case it is

l=(''+location.host).match(/[^.]*\.[^.]*$/)[0]
0
 
VirusMinusCommented:
try swapping document.location with top.location
0
 
GwynforWebCommented:
l=(''+top.location).match(/[^/]+$/)[0]
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
arantiusAuthor Commented:
@gwyn
That doesn't execute in firefox, and in IE it only returns the filename

@Virus
Yeah, that does save 5 bytes =)
0
 
GwynforWebCommented:
what are you trying to extract from the location string?  (it looked the file name to me)
0
 
GwynforWebCommented:
0
 
arantiusAuthor Commented:
yes, exactly.  i want the "domain name" with any sub domains stripped.
ebay.com for: www.ebay.com, signin.ebay.com, scgi.ebay.com, ebay.com

Etc.
0
 
GwynforWebCommented:
in which case it is the above eg

javascript:function x(){alert(l=(''+location.host).match(/[^.]*\.[^.]*$/)[0])}x()
0
 
arantiusAuthor Commented:
Beautiful Gwyn =)  Don't think it can get much smaller than that !
0
 
devicCommented:
and what's about port? e.g. :8080
0
 
GwynforWebCommented:
Thanks for the points
0
 
GwynforWebCommented:
Above submitted from Netscape using

javascript:function x(){document.getElementsByTagName('textarea')[0].value+='Thanks for the points';document.answerQuestionForm.submit()}x()
0
 
GwynforWebCommented:
to answer Devic (port number was not in question code)

l=(''+location.hostname).match(/[^.]*\.[^.]*$/)[0]
eg
javascript:function x(){alert(l=(''+location.hostname).match(/[^.]*\.[^.]*$/)[0])}x()
0
 
devicCommented:
Gwyn, I use always oldlook and adress is :
http://oldlook.experts-exchange.com:8080/Web/Web_Languages/JavaScript/Q_21189116.html
now it works correct ;)
0
 
GwynforWebCommented:
:-)
0
 
GwynforWebCommented:
this also seems to work with the hostname

l=location.host.match(/[^.]*\.[^.]*$/)[0]

javascript:function x(){alert(l=location.host.match(/[^.]*\.[^.]*$/)[0])}x()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.