0

I'm developing a Chrome extension. I need to clear a popup, the usual way I would do that is to change the contents of body to " " with document.getElementsByTagName('body')[0].innerHTML = '';

But I cannot do this because all content is in a javascript file.

I display some images using the following (just with varying images and styling): var img = document.createElement("img"); img.src = "info_screen.png"; img.alt = 'Information Screen'; document.body.appendChild(img);

I need to clear the popup, the issue is that I cannot use the above mentioned method (due to there being a lack of an HTML file). I looked into possibly clearing the contents of the function that included that code yet all I could find was How do I clear the content of a div using JavaScript? and Creating an element that can remove it self? yet neither suit my situation due to one asking to clear the contents of div (I don't even have an html file) and the other being to create an element that removes itself as opposed to a function. I have tried countless times to adapt the second method to function for my use-case yet none seem to succeed. How would I go about clearing the contents of this popup?

3. 5
  • 11
  • 5
  • A line in your question says "Then clear the popup with:" and some code. Then later you say you can't do that. This question doesn't really make any sense. – Pointy Aug 29 '20 at 12:47
  • @Pointy I first clear the popup with that but I need to clear it again. I just had that there for some context, I'll make it more clear now. – 3. 5 Aug 29 '20 at 12:49
  • try not removing the body at the beginning, but replacing its content with the images, and leaving the method of removing it for the end when really necessary, if you say it only works once, apply it only once at the end – Jesus Alfonso Pinto Delgado Aug 29 '20 at 12:52
  • If you can clear the document content by setting `document.body.innerHTML` to an empty string, you can do it again. – Pointy Aug 29 '20 at 12:52
  • @JesusAlfonsoPintoDelgado the code in the question does not remove the `` element. – Pointy Aug 29 '20 at 12:53
  • @JesusAlfonsoPintoDelgado I have changed the content of my post a bit, ignore that first bit where I spoke about first clearing it with that, it was unneeded. I am more focused on clearing the popup by altering the contents of the functions that display my images, however I'm unable to do so as described in the last paragraph of the post. – 3. 5 Aug 29 '20 at 13:00
  • 1
    Just because you don't have an HTML file doesn't mean you don't have DOM elements. – Nathan Hawks Aug 29 '20 at 13:09
  • I suppose I could remove or alter the contents of a function with something like https://stackoverflow.com/questions/15650131/creating-an-element-that-can-remove-it-self considering what @NathanHawks just mentioned. Will give it a go, thanks. – 3. 5 Aug 29 '20 at 13:13

0 Answers0