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

  • Home
  • SEARCH
  • 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 6932369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:41:50+00:00 2026-05-27T11:41:50+00:00

In my web application, users can post text to a feed, and the text

  • 0

In my web application, users can post text to a feed, and the text may include URL’s. My code scans for URL’s and replaces them which anchor tags pointed at the URL’s. I want to change this so that my code can detect whether or not the URL points to an image, and if it does, render an image tag inside the anchor tag, instead of just the URL text.

I can do this on server side code by sending a quick ‘HEAD’ request to the URL to see what the Content-Type is on the response, and this works reliably. However, it doesn’t scale well for obvious reasons.

What would be better is if I could push this logic onto the client’s browser. I’d like to use JavaScript + jQuery to send the ‘HEAD’ request to the specified URL, and read the Content-Type header from the response.

I know that cross-domain requests are an issue. Could I somehow use JSONP? What options do I have?

EDIT – SECURITY RISK

I got some good answers to my question, but I wanted to point out something in big bold letters. As Adam pointed out in the comments, this is a security risk. If you can guarantee the URL’s of the images are all coming from trusted domains, you’re good to go with this solution. However, in my scenario, users can enter whatever URL they want. This means they could create their own site which requires basic authentication, and then when the jQuery runs to set the src attribute on the created image, the user is presented with a username/password dialog, and that’s obviously a huge risk.

  • 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-27T11:41:51+00:00Added an answer on May 27, 2026 at 11:41 am

    You can try to load it in a hidden img element:

    $('<img />').attr('src', url).load(function () { 
        alert('url contains an image'); 
    }).error(function () {
        alert('url is no image');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of a web application users can upload files of data, which generates
In my web application there's a page where users can post messages. The problem
I'm writing a web application where users can submit pictures, videos, and descriptons of
I want to build a web application where users can register and have a
I have an interactive web application powered by jQuery where users can manipulate visual
In my web application, users can download a .tar.gz archive containing the app files.
I have a web application with users and their documents. Each user can have
I'm developing a web application that will enable users to post short status updates
I have a Web application where I can post an Insight that is a
Currently I have a web application where a user can use dropdown lists to

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.