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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:10:31+00:00 2026-05-25T03:10:31+00:00

I am using Ruby on Rails v3.0.9 and jQuery 1.6. I am trying to

  • 0

I am using Ruby on Rails v3.0.9 and jQuery 1.6. I am trying to retrieve and display the favicon image from some web sites.

For instance, in order to do that for a single web site I am using the following code:

$jQ.ajax({
  type:    'GET',
  url:     'http://www.facebook.com/favicon.ico',
  data:    '',
  error:   function(jqXHR, textStatus, errorThrown) {
    $jQ('#facebook_favicon').replaceWith('ERROR');
  },
  success: function(data, textStatus, jqXHR) {
    $jQ('#facebook_favicon').replaceWith("<img width='16px' height='16px' src='http://www.facebook.com/favicon.ico' />");
  }
});

I use the above code that performs an HTTP request in order to check if the favicon was found: if so (on success), it will replace the #facebook_favicon related to an HTML tag with the just found favicon.ico image otherwise it will replace that with an ERROR text.

However, when I load the page where the above JavaScript is placed and I inspect the Firebug Console I get the following:

firebug console errors

It means that the request was successfully performed (HTTP status codes are all 200, except for Gmail) but I can not display the icon image on success. Why? What is the problem?

I noted that in Firebug Responses are all blank, like this:

firebug console errors

What I can do to accomplish what I would like to make (I am referring mostly to check if a web site favicon is found)?


If I use code like the following it will work but it doesn’t check the favicon presence:

$jQ('#facebook_favicon').replaceWith("<img width='16px' height='16px' src='http://www.facebook.com/favicon.ico' />");
  • 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-25T03:10:31+00:00Added an answer on May 25, 2026 at 3:10 am

    You can’t do XmlHttpRequests on URLs that are not on the same domain/port/protocol than the current page.

    You can, however, check that an image exists by using an Image object and the onload and onerror events:

    var img = new Image;
    var src = 'http://www.facebook.com/favicon.ico';
    img.onload = function() {
        // the image exists, display it
    };
    img.src = src;
    

    You can wrap this in a function:

    function imageExists(src, callback) {
        var img = new Image;
        img.onload = function() {
            callback(src, true);
        };
        img.onerror = function() {
            callback(src, false);
        };
        img.src=src;
    }
    

    And use it like this:

    imageExists('http://www.facebook.com/favicon.ico', function(src, exists) {
        if (exists) {
            $('body').append('<p>The image loaded correctly!</p>');
            $('<img>').attr('src', src).appendTo('body');
        } else {
            $('body').append('<p>oops, error</p>');
        }
    });
    

    Test it here: http://jsfiddle.net/YpBsJ/2/

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

Sidebar

Related Questions

I'm using Ruby on Rails with jQuery and trying to do the following: <%=
I am trying to make a auto complete box using ruby on rails, jquery
I am using Ruby on Rails 3.0.9 and jQuery 1.6.2 I am trying to
I am trying to create a photo viewer in Ruby on Rails using jquery-lightbox
I am using Ruby on Rails 3.0.10 and jQuery 1.6. I am trying to
I am using Ruby on Rails 3.1.0 , jquery-rails and WillPaginate gems in order
I am using Ruby on Rails 3.0.10 and jQuery 1.6. I am trying to
I'm using Jquery with Ruby on Rails (3.1) and am having some problem with
I'm trying to write an app using Ruby on Rails and I'm trying to
I am trying to update a record from an index using either jQuery alone

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.