Is it possible to detect if an image has been loaded via:
<img src="image.jpg"/>
Versus in the address bar or linked to directly via:
<a href="image.jpg">Image</a>
Thanks.
Is it possible to detect if an image has been loaded via:
<img src="image.jpg"/>
Versus in the address bar or linked to directly via:
<a href="image.jpg">Image</a>
Thanks.
No, in general it is not.
The browser will issue the exact same request for both.
When the browser parses the HTML (first thing it gets), each additional resource (JavaScript, CSS, image and other linked files) will be requested separately. Browsers do not add information about where they got the reference from - so it is not possible to tell from the request whether it was directly on the address bar or from a reference on an HTML page.
You could query the logs to see if the request is all on its own or if a request to the HTML page (and possibly other resources) have been done around the same time. This is not fool proof (think about the multiple levels of caching we have on the web).
It is possible.
Just check the referrers!
<img src="image.jpg"/>
The referrer will be the page BEFORE the image
<a href="image.jpg">Image</a>
The referrer will be the page where the image is embedded
Otherwise, just add a GET param.
<img src="image.jpg?src=img"/>
<a href="image.jpg?src=a">Image</a>
On the following page with JS or in the apache logs you eval the GET param without any side effects or pitfalls for the user.