Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Byte saving, string manipulation

Posted on 2004-10-30
16
Medium Priority
?
350 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:arantius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 3
  • 2
  • +1
16 Comments
 
LVL 30

Expert Comment

by:VirusMinus
ID: 12455062
try swapping document.location with top.location
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455352
l=(''+top.location).match(/[^/]+$/)[0]
0
 
LVL 18

Author Comment

by:arantius
ID: 12455383
@gwyn
That doesn't execute in firefox, and in IE it only returns the filename

@Virus
Yeah, that does save 5 bytes =)
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 31

Expert Comment

by:GwynforWeb
ID: 12455401
what are you trying to extract from the location string?  (it looked the file name to me)
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455409
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 500 total points
ID: 12455447
in which case it is

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

Author Comment

by:arantius
ID: 12455448
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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455477
in which case it is the above eg

javascript:function x(){alert(l=(''+location.host).match(/[^.]*\.[^.]*$/)[0])}x()
0
 
LVL 18

Author Comment

by:arantius
ID: 12455483
Beautiful Gwyn =)  Don't think it can get much smaller than that !
0
 
LVL 25

Expert Comment

by:devic
ID: 12455689
and what's about port? e.g. :8080
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455691
Thanks for the points
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455693
Above submitted from Netscape using

javascript:function x(){document.getElementsByTagName('textarea')[0].value+='Thanks for the points';document.answerQuestionForm.submit()}x()
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455740
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
 
LVL 25

Expert Comment

by:devic
ID: 12455760
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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12455805
:-)
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12457578
this also seems to work with the hostname

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

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

618 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