Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect if an image has been loaded via img src="... vs address bar / "as the document"?

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.

like image 784
anonymous-one Avatar asked Aug 31 '12 15:08

anonymous-one


1 Answers

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).

like image 83
Oded Avatar answered Nov 01 '22 14:11

Oded