Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15911

Re: Background image in <TD>

Content-Type text/plain; charset="UTF-8"
Message-ID <1831008.B7evb7SvqA@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Sun, 16 Sep 2012 01:54:02 +0200
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Background image in <TD>
Newsgroups comp.lang.javascript
References <5054ed07$0$6897$e4fe514c@news2.news.xs4all.nl>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 109
NNTP-Posting-Date 16 Sep 2012 01:54:02 CEST
NNTP-Posting-Host f2fc58a6.newsspool3.arcor-online.net
X-Trace DXC=BEYbPn^0PVUaAeROF2PWMQMcF=Q^Z^V3X4Fo<]lROoRQ8kF<OcfhCO[e1h`^Sj[7o^DZm8W4\YJN\OG5GDc6?K]P@_=MWQQ2on^A14d]]KebZ[
X-Complaints-To usenet-abuse@arcor.de
Path csiph.com!usenet.pasdenom.info!gegeweb.org!feed.ac-versailles.fr!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Xref csiph.com comp.lang.javascript:15911

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Tom de Neef wrote:

> Following html shows the intended behaviour in IE, FF and Chrome: 
> display an image as background to a <TD> element.
> <html>
> <head><title>test</title></head>
> <body>
> <table border="1" cellpadding="2" cellspacing="3">
>   <tr>
>     <td background='expl.bmp'>test</td>
>   </tr>
> </table>
> </body>
> </html>

This is not Valid HTML.  <http://validator.w3.org/>
 
> I try to achieve this with Javascript but I cannot find the proper way.

There is no Javascript.  <http://PointedEars.de/es-matrix>

>        thisTD.background = "expl.bmp";
> works only with IE.

That has to do with the fact that in proper HTML the TD element has no 
`background' attribute, therefore the DOM object that represents it has no 
standards-compliant `background' property:

<http://www.w3.org/TR/html401/struct/tables.html#edef-TD>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075>

And it has to do with the fact that BitMaP images originate from Windows and 
*Microsoft* Internet Explorer is essentially a *Microsoft* Windows browser:

<http://en.wikipedia.org/wiki/BMP_file_format>

You have omitted the DOCTYPE declaration here, so Internet Explorer would 
use Compatibility Mode in which deprecated or even proprietary features are 
supported (as opposed to Standards Mode, which is more like "Almost 
Standards Mode" – CSS1Compat – with MSHTML).

> I've tried
>        thisTD.style.backgroundImage = "expl.bmp";

This is not supposed to work, see 
<http://www.w3.org/TR/CSS2/colors.html#propdef-background-image>

> and
>        if (thisTD.style.backgroundImage) {

If the element represented by the object referred to by `thisTD' does not 
have a background-image specified in its style attribute, then 
`this.style.backgroundImage' will be the empty string.  The empty string 
when converted to Boolean, as it will be in an `if' statement, is `false'.  
So the following Block statement will never be executed …

>          thisTD.style.backgroundImage = "expl.bmp"
>        }
>        else {thisTD.background = "expl.bmp" }
 
… and this `else' branch will always be executed.  The best way to check for 
the existence of a DOM property is (with few exceptions) a `typeof' test:

  if (typeof thisTD.style.backgroundImage != "undefined")
  {
    // …
  }

However, first the `background' element property (as opposed to the 
`background' style property) is proprietary as is the `background' 
attribute, and second …

> but none works in FF or Chrome.

… BitMaP images (uncompressed) are not supposed to be used on the Web as 
they are far too large by comparison, so browsers usually do not support 
them.

Use JPEG, GIF (both support lossy compression), or PNG (lossless 
compression) instead, then use proper CSS value syntax for the value of the 
DOM property.  You can use applications like The GIMP – <http://gimp.org/> – 
to convert from BMP to one of those image formats.

> Can you pls do a suggestion. (I don't know what DOCTYPE is used - the 
> html is generated by a server. If that's important: how can I find out?).

Use the Source, Luke.  Internet Explorer has Edit → View Source; others have 
similar menu items, and Ctrl+U and similar for a shortcut.  You can enable 
DOCTYPE declaration display with an option in Firebug; Chrome Developer 
Tools (also in the Chromium Browser) show it in the Elements pane by default 
(as light-grey text on white background here).  However, the 
document.compatMode property tells you immediately whether you are in 
Quirks/Compatibility Mode ("BackCompat") or in (Almost) Standards Compliance 
Mode ("CSS1Compat").

If it is actually a server-side application that generates such junk code, 
it is most certainly hopelessly borken and should be replaced.  That said, 
given your position in the learning curve as suggested by your posting, you 
are not in a position to tell who the culprit is.  It may very well be that 
you wrote and/or used a bad – static – template, and the server merely does 
what it is supposed to do – to serve it.


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Background image in <TD> "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-15 23:03 +0200
  Re: Background image in <TD> "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-15 21:13 +0000
  Re: Background image in <TD> SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-09-16 00:21 +0200
  Re: Background image in <TD> Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-16 01:54 +0200
    Re: Background image in <TD> Martin Leese <please@see.Web.for.e-mail.INVALID> - 2012-09-16 11:16 -0600
  Re: Background image in <TD> evlanovsasha@gmail.com - 2012-09-15 17:06 -0700
  Re: Background image in <TD> "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-16 12:48 +0200
    Re: Background image in <TD> "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-16 15:19 +0300
      Re: Background image in <TD> "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-17 09:53 +0200
        Re: Background image in <TD> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-09-17 06:44 -0700
        Re: Background image in <TD> "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-09-17 06:46 -0700
        Re: Background image in <TD> Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-17 21:00 +0200
        Re: Background image in <TD> SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-09-18 02:55 +0200

csiph-web