tags:

views:

83

answers:

3

Ok, lets say I go to http://www.google.com/intl/en_ALL/images/logo.gif , which is not really a document, but an image, iin my browser. Does it still have a document object? Can I use javascript: in my location bar? Wha'ts the deal with this? Thanks.

A: 

no... the browser simply acts as a picture viewer

Philippe Leybaert
but `alert()` works...
Joe
duh... What does that have to do do with there being a DOM?
Philippe Leybaert
+3  A: 

A quick look with Firebug reveals that yes indeed, there is a DOM and a document object. For example, javascript:alert(document.title) in the location bar gives "logo.gif (GIF Image, 276x110 pixels)". This results from the construction of the following document by the browser:

<html>
    <head>
        <title>logo.gif (GIF Image, 276x110 pixels)</title>
    </head>
    <body>
        <img src="http://www.google.com/intl/en_ALL/images/logo.gif" alt="http://www.google.com/intl/en_ALL/images/logo.gif"/&gt;
    </body>
</html>

This is also true in Chrome (with a slightly different string for the title); the HTML is

<html>
    <body style="margin: 0px;">
        <img style="-webkit-user-select: none" src="http://www.google.com/intl/en_ALL/images/logo.gif"&gt;
    </body>
</html>

In IE, it appears that document.title is empty, but javascript:alert(document.body.clientWidth) gives a result equal to the client area of the browser, so it looks like there's a DOM there as well. The HTML is as follows:

<html>
    <head>
        <title></title>
    </head>
    <body>
        <img src="http://www.google.com/intl/en_ALL/images/logo.gif" complete="complete"/>
    </body>
</html>
Domenic
This is extremely implementation-dependent. Internally, some browsers will build a fake HTML page that will display the picture, but you can't rely on that.
Philippe Leybaert
If by "some" you mean "all"... (OK, I haven't tested Presto, but we have Gecko, WebKit, and Trident represented here; it's a pretty safe bet.)
Domenic
You're right that you shouldn't rely on it, however; this is easily the kind of stuff that could be changed in a later version.
Domenic
+1  A: 

It depends on the browser. If you go to that URL in firefox, for example, and open the DOM Inspector, you will see an html, body and img tag; also, typing javascript:alert(document) in the location bar will alert [object ImageDocument]. IE8 exhibits similar behaviour (but alerts just [object]).

Daniel Vandersluis