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 359637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:24:45+00:00 2026-05-12T12:24:45+00:00

Hi all I am not sure how to approach this problem. I have a

  • 0

Hi all I am not sure how to approach this problem. I have a function that is passed an array of HTML img elements. It loops through these images checking the SRC attribute for images using a blank “no image” thumb nail. It then executes an image search using the img tags ALT attribute as the query. The callback function on the search then replaces the Img SRC with the first image result.

I am having problems matching up the correct image with the corresponding search callback. Right now I am just creating arrays and matching the returned search with an index for the images. Since the multiple searches run concurrently, depending on the size of the image or network latency they can fire the call back out of order and mix up the images.

I need an approach that lets me pair individual searches with html elements. Would this be possible using a searchController and multiple imageSearch objects?

Below is an example of the function I am using

google.load('search', '1');

function googleFillBlanks(jqueryImages){

  //namePairs holds the images matching alt text and attachedCount is used for matching up once the call back is fired
  var attachedCount = 0;
  var namePairs = [];

  function searchComplete(searcher){
    if (searcher.results && searcher.results.length > 0) {
       var results = searcher.results;
       var result = results[0];
       $("img[alt='"+namePairs[attachedCount]+"'] ").attr('src', result.tbUrl);
       //jqueryImages.get(0).attr('src', result.tbUrl);
       attachedCount++;
    }
  }

   var imageSearch = new google.search.ImageSearch();

    //restrict image size
    imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
                               google.search.ImageSearch.IMAGESIZE_SMALL);

    imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]);

  jqueryImages.each(function(){
    if($(this).attr('src').substr(-12,8) == 'no_image')
    { 
      namePairs.push($(this).attr('alt'));
      imageSearch.execute($(this).attr('alt'));
    }
  });
}
  • 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-05-12T12:24:46+00:00Added an answer on May 12, 2026 at 12:24 pm

    this is what I ended up doing encase any one is interested and for self reminder

    google.load('search','1');
    function checkImages(){
    
     // Here is the closure!
     var myClosure = function(img){return function(){
      if(this.results&&this.results.length>0){
       var result = this.results[0];
       img.src = result.tbUrl;
       img.alt = result.titleNoFormatting;
      }
     }};
    
     var imgs = document.getElementsByTagName('img');
     for(var i=0;i<imgs.length;i++){
      var img=imgs[i];
      if(img.src.match(/no_image.{4}/)){
       var is = new google.search.ImageSearch();
       is.setSearchCompleteCallback(is, myClosure(img));
       is.execute(img.alt);
      }
     }
    }
    google.setOnLoadCallback(checkImages);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not entirely sure what is the best approach to this problem, so hopefully
Not sure this is a programming question, but we use LaTeX for all our
I'm sure we all have received the wonderfully vague Object reference not set to
I have a Visual Studio (2008) solution consisting of several projects, not all in
I have a Visual Source Safe repository, and some (not all, alas!) of my
I want: all links which not contained filename (not .html, .jpg, .png, .css) redirect
My Problem: I have an MVC3 application where all views use a common master
Problem: Extract all html between two headers including the headers html. The header text
I am stumped on this homework problem. I think I have the right answer
I'm not too sure how to ask this question. I need to store 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.