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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:35:50+00:00 2026-05-28T15:35:50+00:00

My webpage gets the content from XML via an AJAX call. I retrieve a

  • 0

My webpage gets the content from XML via an AJAX call. I retrieve a URL from that XML and use it to create an element on the page.

But that URL can look like:

  • http://something/something.jpg,
  • or http://something/something.swf

This means it can be a image file or can be a .swf file, so I am unable to display that image or .swf file in same tag (which is also created dynamically).

I don’t know how to display both image and .swf file in same tag. How can I solve this?

  • 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-28T15:35:51+00:00Added an answer on May 28, 2026 at 3:35 pm

    Why don’t you check the URL before creating the tag? You could use a regular expression, like so:

    var url     = 'http://something/something.swf';
    var matches = url.match(/(swf|jpg)$/i);
    
    if (matches.length > 0) {
        var type = matches[0].toLowerCase();
        /* create the img or embed tag, based on `type` */
    }
    

    The i in the regular expression makes it match regardless of case (so it will match “something.SWF” as well) and toLowerCase makes sure we can compare it to a lowercase string (e.g. if (type === 'swf') { }).

    Now you can use the result to create the correct tag, like this:

    var url     = /* extracted from XML, e.g.: */ 'http://something/something.swf';
    var matches = url.match(/(swf|jpg)$/i);
    
    if (matches.length > 0) {
        var type = matches[0].toLowerCase();
        var tag;
    
        // Create the correct tag:
        if (type === 'swf') { 
            tag = $('<embed type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />');
        }
        else if (type === 'jpg') {
            tag = $('<img />');
        }
    
        // Set the src and append to <body>:
        if (tag !== undefined) {
            tag.attr('src', url);
            tag.appendTo('body');
        }
    }
    

    Please keep in mind that this example is untested. For example, you probably need to set the height and width attributed on the <embed> tag.


    NB: match returns an array which contains the entire match, plus any matched groups. In this case, the array will look like this: ['jpg', 'jpg']. That’s because the group, (jpg|swf), which is saved as well as the complete match. If you need to prevent this behaviour, you can use a non-capturing group, like this: (?:jpg|swf), so the group won’t be remembered.

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

Sidebar

Related Questions

I'm trying to retrieve an webpage that has XML data using file_get_contents(). $get_url_report =
I have HTML content coming from a database that gets rendered to a web
I have an ASP.Net HTTPHandler that gets POSTed from a ColdFusion web page whose
WARNING: content not work-appropriate This does not retrieve image successfully from a web page
I have a webpage that pulls information from a database, converts it to .csv
There's a webpage that enables service providers to check customers insurance validity. The page
I'm trying to make a web page that only has content within the page
I'm struggling getting the JSON string that was sent from a web page to
I currently have the following JavaScript/jQuery script that gets an external html page using
I want to make a really script in Python that gets the contents from

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.