Content-Type: text/plain; charset="UTF-8" Message-ID: <1831008.B7evb7SvqA@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn 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+&. 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 Following html shows the intended behaviour in IE, FF and Chrome: > display an image as background to a element. > > test > > > > > >
test
> > This is not Valid HTML. > I try to achieve this with Javascript but I cannot find the proper way. There is no Javascript. > 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: And it has to do with the fact that BitMaP images originate from Windows and *Microsoft* Internet Explorer is essentially a *Microsoft* Windows browser: 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 > 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 – – 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