Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 6 of 6

This is a discussion on Javascript - A Technical Question (For the usual suspects) within the Chrome Tech section, part of the Chrome Chat category: As someone who learnt to program in the mid seventies I was always taught that there are no good or ...


  1. #1
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Smile Javascript - A Technical Question (For the usual suspects)

    As someone who learnt to program in the mid seventies I was always taught that there are no good or bad solutions, only better solutions.

    So my attention was drawn to two bookmarklets on this site that achieve the same objective, namely to emulate McAfee's Site Advisor.

    I've used MSA on IE so am aware of what it is supposed to do.

    As the code for the two solutions is considerably different, but achieves the same results (to me anyway), my question (to you experts out there) is which of the coding is the better and why.

    I in no way want this to be a criticism of the two authors or their respective solutions (we all have our own signature when it comes to programming), it's simply an honest attempt at understanding a little bit about Javascript.

    The two solutions are:

    javascript:void(window.open('http://siteadvisor.com/sites/'+document.location.href.substring(7)));

    javascript: var url=document.location.toString(); var withouthttp=url.substring(7); var subpages=withouthttp.indexOf("/"); var cleanurl=withouthttp.substring(0, subpages); window.open("http://siteadvisor.com/sites/" + cleanurl); document.location=url;

    Look forward to your responses :-D

  2. #2
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Well the second could go without all the variable declarations, and the unnecessary document.location=url; at the end. However there is a difference between the two in that the first sends the site with all the directories and the filename to the site advisor, where the second chops it all off and sends the base url.
    I don't know how site advisor works, maybe it chops all the excess off and checks the main site in it's database, or maybe it checks both.
    They both seem to load just as fast.

    The only suggestion I'd have for the second would be to do something more like:
    javascript:var url=document.location.toString().substring(7); window.open("http://siteadvisor.com/sites/"+url.substr(0,url.indexOf("/")));

    EDIT: Though personally I would've just done it:
    javascript:window.open("http://siteadvisor.com/sites/"+location.host);
    Last edited by Waha; 06-16-2009 at 03:33 AM.

  3. #3
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    I personally like brief bookmarklets. I'd much rather use the first one, not only because it's short and simple, but also because if feels more consuming a web service that way.

  4. #4
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    Thanks for the input Guys, thought the first one would be the preferred solution ...

    Based on my own programming experiences it looked more efficient ...

    BTW Waha ...

    Just for fun tried your edited version, it didn't work ...

  5. #5
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Sorry about that Steve, I misspelled "javascript" I edited my post and it does indeed work now. :P
    EDIT: Oh you meant the first one I posted..forgot a ). lol Didn't really care to test them cause it was just for discussion. ^^;
    Last edited by Waha; 06-16-2009 at 03:34 AM.

  6. #6
    StevePaul's Avatar
    StevePaul is offline Senior Member
    Join Date
    Mar 2009
    Location
    Birmingham, England
    Posts
    1,522

    Default

    That's me for you, never take anything for granted :-D

Similar Threads

  1. Javascript BUG in popup windows
    By bongobongo in forum Bugs and Vulnerabilities
    Replies: 5
    Last Post: 09-06-2010, 07:01 PM
  2. Chrome Plugins Question
    By Neillithan in forum Chrome Plugins
    Replies: 8
    Last Post: 05-31-2009, 01:31 AM
  3. 3D + Javascript + Your web browser
    By Kyrax in forum General Chat
    Replies: 4
    Last Post: 04-23-2009, 02:39 AM
  4. Question: Open new tabs from url
    By peekj in forum Chrome Talk
    Replies: 2
    Last Post: 04-19-2009, 07:17 PM
  5. Google bookmarklets question
    By jackfusion in forum Chrome Tips & Tricks
    Replies: 1
    Last Post: 01-03-2009, 07:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •