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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:59:00+00:00 2026-06-04T23:59:00+00:00

Alright, so I’m trying to make a Chrome extension. I’m quite a bit of

  • 0

Alright, so I’m trying to make a Chrome extension. I’m quite a bit of a noob at this, which is why I’ve started off by taking an example extension from a tutorial site and adding stuff to it. I got it off some site which I can’t remember, if you really want attribution, I can have a search for it. Code:

var req = new XMLHttpRequest();
req.open(
"GET",
"http://api.flickr.com/services/rest/?" +
    "method=flickr.photos.search&" +
    "api_key=90485e931f687a9b9c2a66bf58a3861a&" +
    "text=hello_world&" +
    "safe_search=1&" +  
    "content_type=1&" +  
    "sort=relevance&" +  
    "per_page=24",
true);
req.onload = showPhotos;
req.send(null);

function showPhotos() {
  var photos = req.responseXML.getElementsByTagName("photo");

  for (var i = 0, photo; photo = photos[i]; i++) {
    var img = document.createElement("image");
    img.src = constructImageURL(photo);
    document.getElementById("images").appendChild(img);
  }
}

function constructImageURL(photo) {
  return "http://farm" + photo.getAttribute("farm") +
  ".static.flickr.com/" + photo.getAttribute("server") +
  "/" + photo.getAttribute("id") +
  "_" + photo.getAttribute("secret") +
  "_s.jpg";
}

So anyway, what the extension does is it sends an XMLHttpRequest to Flickr’s API, getting some images (img tags in XML format). It then loops through those tags with a for loop, and for every tag it makes a new img element using createElement(), gives it a src attribute using the constructImageURL() function and appends it to the popup page. What I wanted to do is make it so you can actually click on those images, and be taken to the image’s page. I tried to make a snippet of code based on the one that creates the image elements, but to create anchor (a) elements, which I added to the for loop. It looks like this:

var a = document.createElement("link");
a.href = constructImageURL(photo);
a.target = "_blank";
document.getElementById("images").appendChild(a);

and I then added some code to append the img elements to the anchor elements, effectively making a <a><img /></a> structure:

document.a.appendChild(img);

But, it doesn’t work. Can someone please help?

  • 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-04T23:59:01+00:00Added an answer on June 4, 2026 at 11:59 pm

    Well, you should check the developer tools console by right-clicking the browser action and clicking “Inspect popup” and see what’s wrong.

    I think you might want to use setAttribute, just to make sure. And the element for a link is <a> not <link>, as well as the element for an image is <img> not <image>. Also, you don’t want document.a.appendChild, you want to append the image to the current variable. So it should be something like:

    function showPhotos() {
        var photos = req.responseXML.getElementsByTagName("photo");
        var a = document.createElement("a");
        a.setAttribute("href",constructImageURL(photo));
        a.setAttribute("target","_blank");
    
        var img = document.createElement("img");
        img.setAttribute("src",constructImageURL(photo));
    
        a.appendChild(img);
        document.getElementById("images").appendChild(a);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright. This may be difficult but I have been struggling for quite a bit
Alright, I'll try and make this brief as possible. I wanted to a UIToolbar
Alright, so this is an extension to a question I asked last night. I
Alright, this one's got me seriously stumped, after trying things out for hours with
Alright, I am trying to accomplish this: When a user clicks a button that
Alright, I'm trying to figure out why I can't understand how to do this
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have no idea how to even begin doing this But basically
Alright I created some custom classes for my project sourced from this tutorial ,

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.