Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:27:36+00:00 2026-06-17T16:27:36+00:00

I am new to bookmarklet coding and i have run into a problem where

  • 0

I am new to bookmarklet coding and i have run into a problem where the regular javascript works fine in the browser but not the bookmarklet version.

I had found a bookmarklet which finds a image and turns it into BB code and that works fine, however it loads jQuery and i did not want it doing that all the time. So i was basically just trying to remove the need for it but now it does not work anymore as a bookmarklet.

The original bookmarklet was this:

javascript:document.body.appendChild(document.createElement('script')).src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js';var%20pictureurl=jQuery('img[id$=%22myImage%22]').attr('src');var%20linkurl=document.location.href;alert('%5BURL='+linkurl+'%5D%5BIMG%5D'+pictureurl+'%5B%2FIMG%5D%5B%2FURL%5D');

My javascript which works as regular JS code is:

// Create array variables
var imgs = [];

// Put all of the documents tags in to the arrays
imgs = document.getElementsByTagName('img');

var pictureurl = '';
var linkurl = document.location.href;

for(var i = 0; i < imgs.length; i++){
    var str = imgs[i].getAttribute('id');
    var find = str.search("myImage"); 
    if(find != -1){
        pictureurl = imgs[i].getAttribute('src');
        alert('[URL=' + linkurl + '][IMG]' + pictureurl + '[/IMG][/URL]');
    }
}

When i add javascript: and append the minimized code i can not get it working no matter what i try. If anyone could help me get this working that would be a big help, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:27:38+00:00Added an answer on June 17, 2026 at 4:27 pm

    Yeah, you have an error in your code. I would like to show you how to find it yourself rather than just say where it is, so here goes a micro-tutorial 😉

    1. Strip line comments (//) from your JS code as the bookmarklet will be on one line. You should end up with the code:

      var imgs = [];
      imgs = document.getElementsByTagName('img');
      var pictureurl = '';
      var linkurl = document.location.href;
      for(var i = 0; i < imgs.length; i++){
          var str = imgs[i].getAttribute('id');
          var find = str.search("myImage"); 
          if(find != -1){
              pictureurl = imgs[i].getAttribute('src');
              alert('[URL=' + linkurl + '][IMG]' + pictureurl + '[/IMG][/URL]');
          }
      }
      
    2. Remove new line characters from the code and prefix the code with javascript: protocol so that Chrome knows that the contents is JavaScript code. Your code should now look like this:

      javascript: var imgs = []; imgs = document.getElementsByTagName('img'); var pictureurl = ''; var linkurl = document.location.href; for(var i = 0; i < imgs.length; i++){     var str = imgs[i].getAttribute('id');     var find = str.search("myImage");      if(find != -1){         pictureurl = imgs[i].getAttribute('src');         alert('[URL=' + linkurl + '][IMG]' + pictureurl + '[/IMG][/URL]');     } }
      
    3. Create your bookmarklet as a bookmark and make sure its accessible (i.e. visible so you can click it in any Chrome window).

    4. Go to a page on which you will test your bookmarklet code.
    5. Open Developer tools by holding CTRL + SHIFT + I.
    6. Switch to the tab named Console.
    7. Click the bookmarklet.
    8. The console should now show you the errors/warnings that have been issued while executing the code of your bookmarlet.
    9. In case of your code, it spits:

      Uncaught TypeError: Cannot call method 'search' of null (program):1
      (anonymous function)
      

    Which seems reasonable since search() is invoked on the value of str which contains a value of ID attribute, but not all IMG tags have an id assigned.

    What’s cool is that you can click on the (program):1 on the right hand side of the window and debug the code, inspect variables, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have a javascript bookmarklet to add in a new input
I have a little bookmarklet that opens up a new window, only problem is,
I have the following javascript bookmarklet which opens a new popup window with a
I have a bookmarklet that needs to open a new window/tab. In order to
I have a Javascript bookmarklet that, when clicked on, redirects the user to a
I have a js bookmarklet which works perfectly on all browsers. It spawns a
I am creating a JavaScript bookmarklet that dynamically updates the title bar, but it
i'm making a bookmarklet to my website, and for now i have: <a href=javascript:location.href='http://website.com/compartir_link.php?url='+encodeURIComponent(location.href)
I have written a bookmarklet that receives a Django form and inserts it into
I have a javascript bookmarklet I put together to make an arduous task a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.