I was wondering if it was possible to change an image source on a page based on a url parameter? Perhaps using Javascript?
For example, if we have the default image with an ID?
The scenario would be, http://example.com/page-name/?image-id=specifiedimg
and this would load the image as what the source is set for "specifiedimg"
Hoping that makes sense?
You can specify the image path in the url and then use URLSearchParams to get the image path and then set the image as source to the image element.
for example: http://example.com/page-name.html?image-id=assets/img/something.png
const searchParams = new URLSearchParams(location.search),
imagePath = searchParams.get('image-id'),
image = new Image() // you can use querySelector to target an existing image tag
image.src = imagePath;