0

I have an application that loads an image - the URL of the image however is dynamically generated.

The image URL would look like this (I get the image name through their API): http://openweathermap.org/img/w/10d.png

That URL is created in javascript - how would I make javascript actually get the image from that URL and return the .png so I could display it?

Would ajax be best for this? The solution would have be in regular javascript as the application displaying the image only allows for basic javascript.

Edit: This is for a digital signage solution - so I need to get the .png file into javascript where I will return ThePicture so the signage can display it appropriately. So unfortunately, just adding it to the/a DOM won't work.

Hanny
  • 580
  • 3
  • 16
  • 44
  • Possible duplicate of [How to display dynamic url image in html from which created by javascript](https://stackoverflow.com/questions/44341721/how-to-display-dynamic-url-image-in-html-from-which-created-by-javascript) – dloeda Jun 15 '17 at 15:22
  • It is not a duplicate because I don't need to insert it into a dom - I need to somehow get the image object - it's a digital signage solution, so I'm not displaying to a webpage (unfortunately). – Hanny Jun 15 '17 at 15:24
  • Then Ajax would be useless … since that is a buzzword meaning "Making an HTTP request from a webpage without leaving the page." – Quentin Jun 15 '17 at 15:24
  • Are you saying that you want to create an actual Image() Object then? – Tank Jun 15 '17 at 15:25
  • "The solution would have be in regular javascript as the application displaying the image only allows for basic javascript" — Basic JavaScript has no means to get data in or out of the system. You can't display anything. You can't make HTTP requests. All IO in JS depends on the host environment. You've told us nothing useful about the host environment. – Quentin Jun 15 '17 at 15:25
  • @Tank — That's just a DOM element. It's exactly the same as what you get from `document.createElement`, which the OP has already ruled out. – Quentin Jun 15 '17 at 15:25
  • yes Tank - an actual Image() Object. – Hanny Jun 15 '17 at 15:26
  • @Hanny — Really ?! – Quentin Jun 15 '17 at 15:26
  • @Quentin - I just meant that as far as I can tell (and from documentation) it's all basic javascript, I can't find a way to link an outside library (like jquery). External calls should be fine as long as it can be done in vanilla JS. – Hanny Jun 15 '17 at 15:27
  • @Hanny — There is no way to make an external call with vanilla JS! Browsers provide XMLHttpRequest and fetch, but they are browser extensions, not vanilla JS. Node.js provides HTTP.request, but that's a Node.js extension and not vanilla JS. Other host environments do vary. – Quentin Jun 15 '17 at 15:28
  • Then it would appear I may be up a creek and need to find another solution. I'm willing to entertain other ideas and try things - I just don't know what ideas would be best. – Hanny Jun 15 '17 at 15:29
  • 2
    @Hanny — You need to tell us about the JS environment you are running in. "Unspecified digital signage solution" isn't enough to go on. – Quentin Jun 15 '17 at 15:30
  • It's Haivision Coolsigns - using the content creator software we can make 'content' which pulls from API's, but the ability to 'manipulate' that content is limited to vanilla JS. So I use the openweather API to pull in the icon name and can build the appropriate URL for the image - but I need to 'get' that image to return it for display. – Hanny Jun 15 '17 at 15:44

0 Answers0