SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict jamesglewisf's Avatar
    Join Date
    Sep 2000
    Location
    Big D
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using Bookmarklets to Extract part of the URL

    I'm sorry about the duplicate thread, but there don't seem to be any moderators in the Java and JSP forum. I've asked twice to have my thread moved over here, but they won't. I accidentally posted it to the wrong forum, and it's not getting any responses over there.

    Anyhow, here is my question:

    I read the tutorial on bookmarklets and tried to write one of my own. I'm looking for something to help me when pull out a movie number when I visit IMDb.com using IE6.

    For instance, if I'm visiting this page http://www.imdb.com/title/tt0120737/, I want it to extract the "tt0120737" part of the URL and pop it up in a dialog box.

    I tried this bookmarklet:
    Code:
    javascript:imdbvar=document.location.href.split('/').pop();void(Qr=prompt('IMDB',imdbvar))
    It just returns a blank.

    I tried it with:
    Code:
    javascript:imdbvar=document.location.href.split('/');void(Qr=prompt('IMDB',imdbvar))
    This one gives me the pieces separated by commas, but I don't know how to ge the last piece.

    Unfortunately, I am a javascript novice, so I can't figure out how to make it work.
    Jim Lewis
    To BE or Not to BE, or: How I Learned to Stop Worrying and Love the Barium Enema
    FrappyDoo Forums

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's OK, there aren't any mods here either...
    Code:
    javascript:if(imdbvar=self.location.href.match(/title\/([^\/]+)/))void(Qr=prompt('IMDB',imdbvar[1]));
    ::: certified wild guess :::

  3. #3
    SitePoint Addict jamesglewisf's Avatar
    Join Date
    Sep 2000
    Location
    Big D
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    That's OK, there aren't any mods here either...
    Code:
    javascript:if(imdbvar=self.location.href.match(/title\/([^\/]+)/))void(Qr=prompt('IMDB',imdbvar[1]));
    Thank you, thank you, thank you.

    That works just how I wanted it to.

    Is there a way to make it copy that value to the clipboard?
    Jim Lewis
    To BE or Not to BE, or: How I Learned to Stop Worrying and Love the Barium Enema
    FrappyDoo Forums

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This seems to fly in MSIE:
    Code:
    javascript:cD=window.clipboardData;if(imdbvar=self.location.href.match(/title\/([^\/]+)/))Qr=prompt('Film Number'+(cD?'\nPress OK to Copy':''),imdbvar[1]);if(cD&&Qr)window.clipboardData.setData('Text',imdbvar[1]);void(0);
    A lot more involved in Mozilla...as noted here. You'll need to learn Dutch first.

    The above broken down:

    1) cD=window.clipboardData // IE?
    2) if(imdbvar=self.location.href.match(/title\/([^\/]+)/)) //try to match 'title/' and all non-slash chars after it, assign to 'imdbvar'
    3) 'Film Number'+cD?'\nPress OK to Copy':'' //only add 2nd line to IE (conditional operator)
    4) imdbvar[1] //matched substring (from portion of pattern in parentheses)
    5) if(cD&&Qr) //IE and they didn't click 'cancel'
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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