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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:23:45+00:00 2026-05-30T20:23:45+00:00

I am trying to use JavaScript to upload image to imgur by this example

  • 0

I am trying to use JavaScript to upload image to imgur by this example:

<!DOCTYPE html><meta charset="utf8"><title>Yo.</title>
<div>DROP!<button onclick="document.querySelector('input').click()">Or click</button></div>
<input style="visibility: collapse; width: 0px;" type="file" onchange="upload(this.files[0])">
<script>
/* Drag'n drop stuff */
window.ondragover = function(e) {e.preventDefault()}
window.ondrop = function(e) {e.preventDefault(); upload(e.dataTransfer.files[0]); }
function upload(file) {

    /* Is the file an image? */
    if (!file || !file.type.match(/image.*/)) return;

    /* It is! */
    document.body.className = "uploading";

    /* Lets build a FormData object*/
    var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
    fd.append("image", file); // Append the file
    fd.append("key", "6528448c258cff474ca9701c5bab6927"); // Get your own key http://api.imgur.com/
    var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
    xhr.open("POST", "http://api.imgur.com/2/upload.json"); // Boooom!
    xhr.onload = function() {
        // Big win!
        document.querySelector("#link").href = JSON.parse(xhr.responseText).upload.links.imgur_page;
        document.body.className = "uploaded";
    }
    // Ok, I don't handle the errors. An exercice for the reader.

    /* And now, we send the formdata */
    xhr.send(fd);
}
</script>

<!-- Bla bla bla stuff ... -->

<style>
body {text-align: center; padding-top: 100px;}
div { border: 10px solid black; text-align: center; line-height: 100px; width: 200px; margin: auto; font-size: 40px; display: inline-block;}
#link, p , div {display: none}
div {display: inline-block;}
.uploading div {display: none}
.uploaded div {display: none}
.uploading p {display: inline}
.uploaded #link {display: inline}
em {position: absolute; bottom: 0; right: 0}
</style>

<p>Uploading...</p>
<a id="link">It's online!!!</a>

This example put image url in a link and liked to text “It’s online!!!”

Could you help me how to get the URL of image after uploaded? I want display image URL (e,g replace “It’s online!!!” with the URL) instead of put it in a link.

  • 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-30T20:23:46+00:00Added an answer on May 30, 2026 at 8:23 pm

    Instead of putting setting #link’s href value, set its innerHTML value. Or the innerHTML value of some other element.

    document.getElementById('link').innerHTML = 'The url';
    

    Edit: See http://jsfiddle.net/XVvyJ/1/

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

Sidebar

Related Questions

I am trying to use an HTML form and javascript (i mention this, because
I'm trying to use Javascript to upload a png to imgur . I've used
I'm trying to develop image crop using JQuery. I use ajax to upload the
I'm trying to use javascript as little as possible on this project. I would
I'm trying to use this script from Github at https://github.com/blueimp/jQuery-File-Upload The script has js
I am trying to use JavaScript to start a marquee when a user puts
I have a big red button and I'm trying to use javascript to perform
I am trying to use the flXHR javascript library for making cross-domain calls. I
I'm trying to use the replace function in JavaScript and have a question. strNewDdlVolCannRegion
I'm trying to use Firebug to debug some Javascript that entails blur and focus

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.