[NFBCS] no display in old browser
Brian Buhrow
buhrow at nfbcal.org
Fri Apr 5 16:12:14 UTC 2024
hello. Lynx doesn't understand javascript at all, so your link won't actually fetch the
picture because the page you're downloading contains a link to a javascript program which
browsers capable of understaanding such programs, will execute.
Below is the program.
The following link gets you a jSON document that contains a link to the jpg image itself, as
well as a textual description of the image. I've pasted the contents of what comes back for
April 5, 2024, below. Below that, I've pasted the javascript that fetches this information in
browsers that know about javascript.
Hope this helps.
-Brian
https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY
{"copyright":"Barden Ridge
Observatory","date":"2024-04-05","explanation":"Changes in the
alluring solar corona are detailed in this creative composite image
mapping the dynamic outer atmosphere of the Sun during two separate
total solar eclipses. Unwrapped from the complete circle of the
eclipsed Sun's edge to a rectangle and mirrored, the entire solar
corona is shown during the 2017 eclipse (bottom) seen from Jackson
Hole, Wyoming, and the 2023 eclipse from Exmouth, Western Australia.
While the 2017 eclipse was near a minimum in the Sun's 11 year
activity cycle, the 2023 eclipse was closer to solar maximum. The
2023 solar corona hints at the dramatically different character of
the active Sun, with many streamers and pinkish prominences arising
along the solar limb. Of course, the solar corona is only easily
visible to the eye while standing in the shadow of the Moon. NASA
Coverage: Total Solar Eclipse of 2024 April
8","hdurl":"https://apod.nasa.gov/apod/image/2404/CoronaGraph.jpg","media_type":"image","service_version":"v1","title":"The
Solar Corona
Unwrapped","url":"https://apod.nasa.gov/apod/image/2404/CoronaGraph_1024.jpg"}
const apiKey = 'DEMO_KEY';
const apiUrl = `https://api.nasa.gov/planetary/apod?api_key=${apiKey}`;
function getQueryParam(param) {
const queryParams = new URLSearchParams(window.location.search);
return queryParams.get(param);
}
function displayGreeting() {
const name = getQueryParam('name');
if(name === 'siw') {
document.getElementById('backbutton').innerHTML = '<a href="http://www.shelterislandweather.com">Back to S.I. Weather</a>';
}
if(name === 'sim') {
document.getElementById('backbutton').innerHTML = '<a href="http://www.m.si-weather.com">Back to S.I. Weather</a>';
}
}
async function fetchNasaPictureOfTheDay() {
try {
const response = await fetch(apiUrl);
const data = await response.json();
if(data.media_type === 'image') {
document.getElementById('nasa-image').src = data.url;
document.getElementById('nasa-title').textContent = data.title;
document.getElementById('nasa-explanation').textContent = data.explanation;
if(data.copyright) {
document.getElementById('nasa-copyright').textContent = "Copyright "+data.copyright;
}
} else {
console.log('The fetched media is not an image.');
}
} catch (error) {
console.error('Failed to fetch NASA Picture of the Day:', error);
}
}
window.onload = displayGreeting;
fetchNasaPictureOfTheDay();
More information about the NFBCS
mailing list