HTML DOM revokeObjectURL() method

The URL revokeObjectURL() method releases an existing object URL which was created by using URL createObjectURL(). This method is called when you are finished using an object URL and don’t want the browser to keep the reference to that file any longer.

Syntax:

URL.revokeObjectURL(objectURL);

Parameters:

  • objectURL: A DOMString object URL to be released.

Return Value: This method has no return value.

Example: In this example, create an objectURL using createObjectURL() method and then revoked it.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>URL.revokeObjectURL example</title>
</head>
<body>
  <h1>GeeksforGeeks</h1>
  <input type="file">
  <img>
  <p class="p">The URL of this image is : </p>
</body>
<script>
    var Element = document.querySelector('input');
    var img = document.querySelector('img');
    Element.addEventListener('change', function() {
      var url = URL.createObjectURL(Element.files[0]);
      img.src = url;
      console.log(url);
      URL.revokeObjectURL(url)
      var d=document.querySelector(".p");
      d.textContent+=url;
});
</script>
</html>

chevron_right


Output:

Before Choosing Image:

After Choosing Image: In the console, an error can be seen that “Not allowed to load local resource” as the URL is revoked.

Checking the Object URL will also give “File not found”:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.