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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:13:38+00:00 2026-06-13T23:13:38+00:00

I have a requirement to parse through the entire content and find links and

  • 0

I have a requirement to parse through the entire content and find links and if the links have the extension like pdf, doc, xls, ppt then add the filetype and filesize next to the link.

I found an example of getting the file size using jQuery in Stack Overflow using getResponseHeader("Content-Length") but this one is always returning the same file size for every link.
Anyone has sample for this? Any help is highly appricated.

My current code (I am not checking the extensions still)

<script type="text/javascript">
    $(document).ready(
        function () {
            $('a').each(function (index, obj) {                    
                var eleHref = $(obj).attr('href');
                var extension = eleHref.substr((eleHref.lastIndexOf('.') + 1)).toUpperCase();
                var request;
                request = $.ajax({ type: "HEAD", url: $(eleHref).val(), success:
                function () {
                    $(obj).append(" (" + extension + ", " + parseFloat(request.getResponseHeader("Content-Length") / 1024).toFixed(2) + 'KB)');
                }
                });
            })             
        });            
</script>
  • 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-13T23:13:38+00:00Added an answer on June 13, 2026 at 11:13 pm

    Assuming your images/documents are on the same domain this should work.

    $('a').each(function() {
    
      var $this = $(this)
        , href = $this.attr('href')
        , ext = /(jpg|png|gif|doc|ppt|xls)$/i.exec( href )
        , req;
    
      if ( ext.length ) {
        req = $.ajax({
          type: 'HEAD',
          url: href,
          success: function() {
            var size = +req.getResponseHeader('Content-Length') / 1024 + 'KB';
            $this.append('<span>Extension: '+ ext +'</span>')
                 .append('<span>Size: '+ size +'</span>');
          }
        });
      }
    
    });
    

    Edit: If you want you can map the extensions to an object to pull more info:

    var extensions = {
      ppt: 'Microsoft PowerPoint',
      doc: 'Microsoft Word',
      pdf: 'Adobe Portable Document Format',
      ...
    };
    

    And then:

    ...
    $this.append('<span>Extension: '+ extensions[ ext ] +'</span>')
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to parse html content using javascript? I have a requirement
I have a requirement to parse the content out of Dreamweaver templates. I'm using
I have requirement where some times I would like to load children as well
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field
I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched
We have a requirement to parse a file and write the data to an
We have a special requirement in a project where we have to parse a
I have a requirement to both parse existing XML strings (retrieved from a database)
Possible Duplicate: How can I parse this JSON in Android? I have a requirement,
I have to read a text file and then to parse it, in C#

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.