Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #15914
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Background image in <TD> |
| Date | 2012-09-16 15:19 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <k34g55$u30$1@dont-email.me> (permalink) |
| References | <5054ed07$0$6897$e4fe514c@news2.news.xs4all.nl> <5055ae9a$0$6850$e4fe514c@news2.news.xs4all.nl> |
2012-09-16 13:48, Tom de Neef wrote:
> I used a combination of your suggestions: url( ), changed bmp to png, placed
> the image reference in a global style definition and achieve the desired
> effect by changing the className of the TD element.
So what did we learn? *I* learned, through my testing inspired by this
thread, that the old BMP format is still widely supported, to my mild
surprise; even Android supports it. So changing the image format is not
relevant to the problem; the choice of format is a different issue and
should depend on the nature of the image.
Let's consider items and questions in your original post:
"<td background='expl.bmp'>test</td>"
This is nonstandard but widely supported by browsers. There's hardly any
reason to use it any more, now that you can use CSS and there's a chance
that some future browser implements the specifications more strictly
than popular browsers.
And there's really no reason "to achieve this with Javascript", unless
you want to do it dynamically (as this message of yours suggests, but
the original one didn't).
"I try to achieve this with Javascript but I cannot find the proper way.
thisTD.background = "expl.bmp";
works only with IE."
If you use inspection mode (F12) e.g. in Firefox or Chrome, you will see
that the element node does not contain the property "background". So the
support to the nonstandard background attribute is not reflected in the
DOM in browsers in general (except IE).
So you were right when trying to use the style property instead, because
that's as standard as you can get:
"I've tried
thisTD.style.backgroundImage = "expl.bmp";"
What is really needed here is just to put the image URL in the url(...)
notation, as per CSS specifications:
thisTD.style.backgroundImage = "url(expl.bmp)"
The rest of the thread is just confusion or distraction or, at best,
about unrelated issues. Whatever "placed the image reference in a global
style definition" means, it is apparently irrelevant to the issue.
You could alternatively set thisTD.style.background (which is different
in the sense of setting all other background properties to their initial
values).
You also wrote:
"(I don't know what DOCTYPE is used - the html
is generated by a server. If that's important: how can I find out?)."
It's surely important, because Quirks vs. Standards Mode is affected by
it, and this means dozens of essential differences in browser behavior, see
http://www.cs.tut.fi/~jkorpela/quirks-mode.html
You can see the DOCTYPE by viewing the HTML document source in a
browser. It's on the first line there (or should be, to make all
browsers go to Standards Mode.
In JavaScript, you can use the document.doctype object to inspect the
DOCTYPE declaration in a structured form (of type DocumentType). But you
probably don't want to do that. What really matters is the browser mode,
and for this the de-facto standard is the variable document.compatMode;
it has a string value, and the value "CSS1Compat" indicates Standards
Mode (for obscure historical reasons).
--
Yucca, http://www.cs.tut.fi/~jkorpela/
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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