By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Passing parameters to style sheet, e.g. "mystyle.css?color=ffffff"

P: n/a
How can I pass parameters to a style sheet? I have noticed a couple
of sites are now passing variables to the style sheet, which appear to
be substituted at run time. For example:

<link rel="stylesheet" type="text/css"
href="mystyle.css?color=ffffff">

I have seen references in my temp Internet file directory that
indicates this is possible, but I can't find any documentation how to
do it.

I suspect the mystyle.css page is really an asp or aspx page they does
a substitution with via something like <%=
Request.QueryString("color")%>, but I can't get this to work.

Thanks,

Roger
Jul 21 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a

"Roger" <rj*****@viewcentral.com> wrote in message
news:ef**************************@posting.google.c om...
How can I pass parameters to a style sheet? I have noticed a couple
of sites are now passing variables to the style sheet, which appear to
be substituted at run time. For example:

<link rel="stylesheet" type="text/css"
href="mystyle.css?color=ffffff">

I have seen references in my temp Internet file directory that
indicates this is possible, but I can't find any documentation how to
do it.

I suspect the mystyle.css page is really an asp or aspx page they does
a substitution with via something like <%=
Request.QueryString("color")%>, but I can't get this to work.


I'd think it would have to be that. But then you'd need to configure your
web site to treat requests with the .CSS extension as ASP(X) requests, and
would need to add

<% Response.ContentType = "text/css" %>

at the top of the CSS file. Alternatively you could skip the .CSS extension,
and have

href="mystyle.asp?color=#ffffff"

Then you could skip the server configuration part and just set the content
type and rename mystyle.css to mystyle.asp.
Jul 21 '05 #2

P: n/a
Thanks Harlan. Simply using an .asp page instead of a .css page allows
the query string process and appears to work, at least under IE 6.

Do you think any browsers are sensitive to the .css extension, or
should all browswers access any style sheet reference, as long as the
reference in the html file is correct and the style sheet has the
correct syntax?

Thanks again,

Roger

Jul 21 '05 #3

P: n/a

<rj*****@viewcentral.com> wrote in message
news:10*********************@c13g2000cwb.googlegro ups.com...
Thanks Harlan. Simply using an .asp page instead of a .css page allows
the query string process and appears to work, at least under IE 6.

Do you think any browsers are sensitive to the .css extension, or
should all browswers access any style sheet reference, as long as the
reference in the html file is correct and the style sheet has the
correct syntax?


The latter. All the browser does is send a request for the named resource
back to the server verbatim. The same technique works for dynamically
generating images, by putting the URL for an image-generating ASP file in
the SRC attribute of an IMG tag.

Jul 21 '05 #4

P: n/a
Harlan Messinger wrote:
<rj*****@viewcentral.com> wrote in message
news:10*********************@c13g2000cwb.googlegro ups.com...
Thanks Harlan. Simply using an .asp page instead of a .css page allows
the query string process and appears to work, at least under IE 6.

Do you think any browsers are sensitive to the .css extension, or
should all browswers access any style sheet reference, as long as the
reference in the html file is correct and the style sheet has the
correct syntax?

The latter. All the browser does is send a request for the named resource
back to the server verbatim. The same technique works for dynamically
generating images, by putting the URL for an image-generating ASP file in
the SRC attribute of an IMG tag.

yes, It Works (tm) but is it The Right Way (tm)

--
-----------------------------------------
Visit my site! http://solid.bounceme.net
-----------------------------------------
Jul 21 '05 #5

P: n/a
StarQuake <st*******@antispam.tiscali.nl>:
| href="mystyle.asp?color=#ffffff"
yes, It Works (tm) but is it The Right Way (tm)


On the web file extensions are meaningless, MIME types count. (IE
sometimes thinks it knows better, though.) In URLs you should not mention
your serverside technonlogies, so .php, .asp etc should, if at all, only
occur if it is a link to the non-interpreted source.

--
No sig today, my .sig has gone away
The divider stands forlorn, a symbol of the dawn
No sig today, it seems a common sight
But people reading by don't know the reason why
Jul 21 '05 #6

P: n/a
rj*****@viewcentral.com wrote:
Thanks Harlan.
For what? Please include a bit (but not all) of the message you're
replying to so that we have some context.
Simply using an .asp page instead of a .css page allows the query
string process and appears to work, at least under IE 6.

Do you think any browsers are sensitive to the .css extension,
In a www client (e.g., a web browser), there is no file extension, only
a url and a mime type to tell the client what kind of resource it is.
should all browswers access any style sheet reference, as long as the
reference in the html file is correct and the style sheet has the
correct syntax?


They should all do it, and most do. MSIE/Win -- which is not really a
browser, but sort of acts like one at times -- violates the standard by
ignoring the mime type in favor of content sniffing. MS claims that the
latest "security" [1] pack fixes this, but appears to introduce other
broken stuff to replace what they've fixed. In particular, they advise
web authors to use the correct file extension for web resources. That's
utter nonsense on the client end; as I said above, there is no file
extension to interpret.

Note that some versions of Firefox and Opera have begun to copy
MSIE/Win's broken behavior with regard to css, overriding text/plain and
treating it as css if that's what it appears to be.
[1] It's hard to use "MS" and "security" in the same sentence without
falling off my chair in hysterical laughter.

--
Brian (remove "invalid" to email me)
Jul 21 '05 #7

P: n/a
Brian <us*****@julietremblay.com.invalid>:

MSIE/Win (...) violates the standard by
ignoring the mime type in favor of content sniffing.


Actually IE doesn't ignore the MIME type completely, but uses it as just a
minor type indicator. Sad enough.

--
"Space may be the final frontier,
but it's made in a Hollywood basement."

Red Hot Chili Peppers - Californication
Jul 21 '05 #8

P: n/a

"StarQuake" <st*******@antispam.tiscali.nl> wrote in message
news:2t*************@uni-berlin.de...
Harlan Messinger wrote:
<rj*****@viewcentral.com> wrote in message
news:10*********************@c13g2000cwb.googlegro ups.com...
Thanks Harlan. Simply using an .asp page instead of a .css page allows
the query string process and appears to work, at least under IE 6.

Do you think any browsers are sensitive to the .css extension, or
should all browswers access any style sheet reference, as long as the
reference in the html file is correct and the style sheet has the
correct syntax?

The latter. All the browser does is send a request for the named resource back to the server verbatim. The same technique works for dynamically
generating images, by putting the URL for an image-generating ASP file in the SRC attribute of an IMG tag.

yes, It Works (tm) but is it The Right Way (tm)


Absolutely. It's a URL, there's no restriction on what kind of URL it is,
and there's *no reason* why the browser should pre-inspect it. It's none of
the browser's business.

Jul 21 '05 #9

P: n/a
On Wed, 20 Oct 2004, Christoph Paeper wrote:
Brian <us*****@julietremblay.com.invalid>:

MSIE/Win (...) violates the standard by
ignoring the mime type in favor of content sniffing.


Actually IE doesn't ignore the MIME type completely,


Prior to XP SP2, MS documents its violation of the mandatory HTTP
requirements for a specific list of 26 MIME types, although it hints
that it reserves the right to compromise other MIME types too, if and
when it feels like it.

http://msdn.microsoft.com/workshop/n...appendix_a.asp

Indeed when I tried it back then (in NT4) it did indeed behave as
documented. If you chose some preposterous MIME type which MS hadn't
yet heard of, you could associate it with an appropriate helper
application, and, under these limited conditions, IE would give a
remarkable impression of being a WWW browser. For example, I told
MSIE that it should open documents of type application/xhtml+xml by
using Mozilla. This worked fine: behind the scenes, IE saves the data
to a temporary file, and then fires up Mozilla to open the document
from its temporary file location.

I have some discussion at
http://ppewww.ph.gla.ac.uk/~flavell/...tent-type.html

But surely you're going to ask why not browse the web using Mozilla in
the first place, and I could only agree. I basically reserve IE for
visits to Windows Update these days.

It's clear that in XP SP2 they haven't actually solved the problem
that they had created before; but they seem to have introduced a new
bunch of brokenness. I haven't seen any clear documentation yet of
what they claim to have done. Just the usual anodyne woffle that MS
knows best what the user wants (and by implication that the IETF
couldn't tell a security exposure from a hole in the ground. It would
be funny if it wasn't so serious.)
Jul 21 '05 #10

P: n/a
Brian wrote:
MS claims that the latest "security" [1] pack fixes this


That should be "service pack". So, as it turns out, I don't need to use
"security" and "MS" in the same sentence. ;-)

--
Brian (remove "invalid" to email me)
Jul 21 '05 #11

P: n/a
Christoph Paeper wrote:
Brian:

MSIE/Win (...) violates the standard by ignoring the mime type in
favor of content sniffing.

Actually IE doesn't ignore the MIME type completely, but uses it as
just a minor type indicator.

Before SP2, MSIE *ignored* the MIME type entirely, unless other methods
(such as content sniffing) failed.

--
Brian (remove "invalid" to email me)
Jul 21 '05 #12

P: n/a
On Wed, 20 Oct 2004, Brian wrote:
Before SP2, MSIE *ignored* the MIME type entirely,
That's not correct - it's worse than that: they actually /tested/ the
MIME type against a list of 26 MIME types before deciding to ignore
it. Any remaining MIME types not on that list were (with some bizarre
exceptions related to plugins) handled correctly (including, just to
rub salt into the wound, content types like application/msword,
application/vnd.ms-excel - even text/rtf was not in their hitlist for
this IETF-violating behaviour).

So, far from "ignoring" the MIME type, they took a close look at it
before deciding to violate the interworking mandates by tossing it
aside.
unless other methods (such as content sniffing) failed.


Not that either: if content sniffing failed, their last resort still
didn't involve the original MIME type (for the dread 26 types on their
hit list). Sometimes, however, it involved what they interpreted as
the filename extension (which of course for HTTP is defined by the RFC
to be irrelevant when there's a MIME type present - which means
essentially "all of the time" nowadays).
Jul 21 '05 #13

P: n/a
Unfortunately, using an asp page for a style sheet does not appear to
work for FireFox v 1.0. If I attempt to reference the style sheet as
<link rel="stylesheet" type="text/css" href="mystyle.asp"> it does not
pick up the style sheet. However, the reference <link rel="stylesheet"
type="text/css" href="mystyle.css"> works fine. Both of these work
fine with IE.

It appears IE does not seem to care what the extension is for the style
sheet, but FireFox does.

Roger

Jul 21 '05 #14

P: n/a
<rj*****@viewcentral.com> wrote:
Unfortunately, using an asp page for a style sheet does not appear to
work for FireFox v 1.0. If I attempt to reference the style sheet as
<link rel="stylesheet" type="text/css" href="mystyle.asp"> it does not
pick up the style sheet. However, the reference <link rel="stylesheet"
type="text/css" href="mystyle.css"> works fine. Both of these work
fine with IE.

It appears IE does not seem to care what the extension is for the style
sheet, but FireFox does.


The problem isn't ASP per se, nor is it the .asp filename extension. The
problem is almost certainly that "mystyle.asp" is being sent with the wrong
MIME type.

See http://css.nu/faq/ciwas-aFAQ.html#QA05
--
Darin McGrew, mc****@stanfordalumni.org, http://www.rahul.net/mcgrew/
Web Design Group, da***@htmlhelp.com, http://www.HTMLHelp.com/

"It's easier to stay out than to get out." - Mark Twain
Jul 21 '05 #15

P: n/a
rj*****@viewcentral.com wrote:
Thanks Harlan. Simply using an .asp page instead of a .css page
allows the query string process and appears to work, at least under
IE 6.

Do you think any browsers are sensitive to the .css extension, or
should all browswers access any style sheet reference, as long as the
reference in the html file is correct and the style sheet has the
correct syntax?

Thanks again,

Roger


Mozilla (I think) doesn't pick up that a .php/.asp file contains css data
unless you send it with "Content-Type:text/css"
Jul 21 '05 #16

P: n/a
rj*****@viewcentral.com wrote:
Unfortunately, using an asp page for a style sheet does not appear to
work for FireFox v 1.0. If I attempt to reference the style sheet
as <link rel="stylesheet" type="text/css" href="mystyle.asp"> it does
not pick up the style sheet.
Url? I imagine that the stylesheet is sent with the wrong MIME type.
Fix that and it will work in Firefox.
However, the reference <link rel="stylesheet" type="text/css"
href="mystyle.css"> works fine.
Firefox mimics IE in a small subset of cases, where the resource is
likely to be css. I think the MIME type sent with the resource must be
text/plain as well in order to trigger Firefox's guessing mechanism, but
I can't be sure in light of what you've reported. Furthermore, it
appears that the resource url must end in ".css", though I can't be sure
without a url to test.
Both of these work fine with IE.
Of course. It sniffs content in any case, but only for certain MIME
types as A. Flavell explained. See his post of 20 Oct 2004 for his
remarks, including a correction of what I wrote earlier.
It appears IE does not seem to care what the extension is for the
style sheet
First, let's be clear: there is no extension on the www. There is a
resource and its url. That's it. File names, including extensions, are
only applicable on a filesystem.
but FireFox does.


Only where it chooses to try to guess the type, and only in certain
versions, and only for css. There was a time when Mozilla obeyed the
relevant standards entirely, and never tried to second guess the MIME
header. Alas, it, along with Opera, have followed IE, no doubt in an
attempt to make it appear that their browsers "work" when in fact, in
this matter, they are all broken.

--
Brian (remove "invalid" to email me)
Jul 21 '05 #17

P: n/a
Alan J. Flavell wrote:
On Wed, 20 Oct 2004, Brian wrote:

Before SP2, MSIE *ignored* the MIME type entirely,

That's not correct - it's worse than that: they actually /tested/ the
MIME type against a list of 26 MIME types before deciding to ignore
it.


I forgot about that part. Thanks for the correction.
Any remaining MIME types not on that list were (with some bizarre
exceptions related to plugins) handled correctly (including, just to
rub salt into the wound, content types like application/msword,
application/vnd.ms-excel -
That is just plain rediculous. application/msword can be trusted, but
text/plain cannot? Sheesh.
So, far from "ignoring" the MIME type, they took a close look at it
before deciding to violate the interworking mandates by tossing it
aside.
Right. I was thinking of this behavior of tossing the MIME type aside
when I wrote "ignore", but your explanation is clearer.
unless other methods (such as content sniffing) failed.

Not that either: if content sniffing failed, their last resort still
didn't involve the original MIME type


Perhaps my memory fails me. I thought that using the MIME type header
was on their list of things to use when content sniffing failed. But I
cannot read mail or surf the web easily from my laptop computer, where I
bookmarked the MS documentation of this behavior, so I cannot check it.
Sometimes, however, it involved what they interpreted as the filename
extension


I thought that was actually *below* MIME type, which was itself below
(by several steps) content sniffing. Again, I'm working from memory,
which isn't (apparently!) what it used to be.

In any case, the change in SP 2 seems to have reemphasized the
importance of file extension, with no clear definition of extension on
the www. Ho hum.

--
Brian (remove "invalid" to email me)
Jul 21 '05 #18

P: n/a
Brian <us*****@julietremblay.com.invalid> wrote:
Only where it chooses to try to guess the type, and only in certain
versions, and only for css. There was a time when Mozilla obeyed the
relevant standards entirely, and never tried to second guess the MIME
header. Alas, it, along with Opera, have followed IE, no doubt in an
attempt to make it appear that their browsers "work" when in fact, in
this matter, they are all broken.


It's a GUI pref option in Opera, I assume that Firefox can also be made
to behave.

--
Spartanicus
Jul 21 '05 #19

P: n/a
On Thu, 21 Oct 2004, Brian wrote:
Alan J. Flavell wrote:
On Wed, 20 Oct 2004, Brian wrote:
unless other methods (such as content sniffing) failed.


Not that either: if content sniffing failed, their last resort still
didn't involve the original MIME type


Perhaps my memory fails me.


I think the fault was mine, sorry.

http://msdn.microsoft.com/workshop/n...appendix_a.asp

Their literally "last" resort (step 6) doesn't actually involve
the server-provided MIME type at all. But some of the earlier steps
-do- involve some assessment of (rather than total disregard of) the
server-provided MIME type, and I'd forgotten that.
I thought that using the MIME type header
was on their list of things to use when content sniffing failed.
Steps 3, 4, and 5 as described in their woffle seem to be complicated,
even assuming that they accurately reflect what happens. You're right
that the server-provided MIME header is still being used for some
purposes within these steps. Step 2 is the one where the MIME type,
having been inspected and found to be on their hit-list, is then
disregarded "if one of the hard-coded [content-sniffing] tests
succeeded".
In any case, the change in SP 2 seems to have reemphasized the
importance of file extension, with no clear definition of extension
on the www. Ho hum.


Indeed. No wonder that they also fall foul of these virus
attachments[1] with file names like "document.txt
..scr"

sigh.
[1] "attackments" is perhaps le typo juste.
Jul 21 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.