Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Dynamically created ASP stylesheet not working in Firefox

  • 12 replies
  • 5 have this problem
  • 4 views
  • Last reply by Ally

more options

I've got a dynamically created stylesheet (I pass in variables for starting font size, header colors, etc.) that works perfectly in IE but is ignored in Firefox. The dynamic stylesheet worked fine until we had to add a <doctype> to our pages in order to use JQuery.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Now, it's simply ignoring the .asp stylesheet include. I can see it in the source code, but the page displays in default style.

<link rel="stylesheet" type="text/css" media="all" href="/include/styles.asp?d=<%= g_strDarkColor %>&m=<%= g_strMediumColor %>&l=<%= g_strLightColor %>&c=<%= g_strContrastColor %>&link=<%= g_strLinkColor %>&f=<%= g_intBaseFontSize %>&h=<%= g_strHeadingColor %>&r=<%= g_strRHTextColor %>&line=<%= g_strLineColor %>&sb=<%= g_strSeparatorBarColor %>&in=<%= g_intImageNumber %>&mi=<%= g_strNavBgImage %>" />

resolves to:

<link rel="stylesheet" type="text/css" media="all" href="/include/styles.asp?d=333333&m=FF0000&l=FF0000&c=FF0000&link=164072&f=20&h=F07915&r=666666&line=CCCCCC&sb=999999&in=1&mi=bg_1" /> 

Is there some sort of tag I'm missing that will make Firefox recognize the stylesheet or am I just out of luck and will have to give up JQuery or make manual stylesheets?

Thank you for ANY help!

I've got a dynamically created stylesheet (I pass in variables for starting font size, header colors, etc.) that works perfectly in IE but is ignored in Firefox. The dynamic stylesheet worked fine until we had to add a <doctype> to our pages in order to use JQuery.<br /> <br /> <pre><nowiki><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> </nowiki></pre> Now, it's simply ignoring the .asp stylesheet include. I can see it in the source code, but the page displays in default style.<br /> <br /> <pre><nowiki><link rel="stylesheet" type="text/css" media="all" href="/include/styles.asp?d=<%= g_strDarkColor %>&m=<%= g_strMediumColor %>&l=<%= g_strLightColor %>&c=<%= g_strContrastColor %>&link=<%= g_strLinkColor %>&f=<%= g_intBaseFontSize %>&h=<%= g_strHeadingColor %>&r=<%= g_strRHTextColor %>&line=<%= g_strLineColor %>&sb=<%= g_strSeparatorBarColor %>&in=<%= g_intImageNumber %>&mi=<%= g_strNavBgImage %>" /></nowiki></pre> resolves to: <pre><nowiki><link rel="stylesheet" type="text/css" media="all" href="/include/styles.asp?d=333333&m=FF0000&l=FF0000&c=FF0000&link=164072&f=20&h=F07915&r=666666&line=CCCCCC&sb=999999&in=1&mi=bg_1" /> </nowiki></pre> Is there some sort of tag I'm missing that will make Firefox recognize the stylesheet or am I just out of luck and will have to give up JQuery or make manual stylesheets? Thank you for ANY help!

Modified by cor-el

All Replies (12)

more options

The server probably is misinforming Firefox about the file by sending the content-type header text/html. You need your ASP script to send the content-type header text/css as the first thing sent to the browser. Try this:

At the top of your styles.asp file on the server, the first two lines should be:


<% Response.ContentType = "text/css"

(Actually, an HTML comment could be placed before the above if necessary, for example, the comment that incorporates the ADO object type library. But it is best to avoid any line breaks outside the comment tag.)

Any luck?

more options

So I put this at the top of my styles.asp: <% Response.ContentType = "text/css"

and then I already had:

Language = VBScript Option Explicit Dim variables......

but same result. Any other ideas? Does it need the language line? And thank you for the quick reply, btw...it's appreciated!

more options

Actually, adding that line in make IE not recognize the style sheet. Grrr...why can't they all play nicely together!

more options

Oh, I assumed you were using the % tags. If you place your ASP code in <script> tags with runat="server", you will need to close the code I gave you:


&lt% Response.ContentType = "text/css" %>

Does that work?

Edit: By the way, I assumed ASP Classic based on the file extension. If this is a .Net page, the syntax for adding a header is a bit different.

Modified by jscher2000 - Support Volunteer

more options

No. But maybe I don't have my stylesheet high enough in the overall code base. Here's a view of the "view source". It's the last item in this post:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>liveandworkwell.com</title>
 
	<!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />	
    
	<meta name="language" content="en" />
    
	<meta name="language" content="spanish" />
    -->
 
	<script type="text/javascript" src="/include/jquery.tools.min.js"></script>
	<script type="text/javascript" src="/include/jkmegamenu.js"></script>
 
 
	<link rel="stylesheet" type="text/css" media="all" href="/include/reset.css" />
	<link rel="stylesheet" type="text/css" media="all" href="/include/clearfix.css" />
	<link rel="stylesheet" type="text/css" media="all" href="/include/fonts.css"  />
	
	
	<script type="text/javascript">
	    //megamenu.definemenu("anchorid", "menuid", "mouseover|click")
	    jkmegamenu.definemenu("megaanchor1", "megamenu1", "mouseover")
	    jkmegamenu.definemenu("megaanchor2", "megamenu2", "mouseover")
	    jkmegamenu.definemenu("megaanchor3", "megamenu3", "mouseover")
	</script>
 
 
	
		<link rel="stylesheet" type="text/css" media="all" href="/include/styles.asp?d=333333&m=FF0000&l=FF0000&c=FF0000&link=164072&f=12&h=F07915&r=666666&line=CCCCCC&sb=999999&in=1&mi=bg_2" />

Modified by cor-el

more options

The last linked style sheet in your page should override the earlier ones, so there's no problem there.

I'm only focusing on the styles.asp script itself. IIS normally sends the text/html header with a .asp page, so you have to override that in the page itself.

If you are using an editor that doesn't show the raw code, then my comments probably don't make sense. Try editing the file in WordPad or your favorite text editor.

more options

I use an HTML editor. Here's the top of my actual styles.asp, maybe you can see if I'm doing something wrong (the issue with Firefox wouldn't have anything to do with the fact that I'm using 'em' rather than 'px' as my measurement, would it?):

<% Response.ContentType = "text/css" %>
<%@ Language=VBScript %>
<%
Option Explicit

Dim strDarkColor	        :	strDarkColor = ""
Dim strMediumColor	        :	strMediumColor = ""
Dim strLightColor	        :	strLightColor = ""
Dim strContrastColor        :	strContrastColor = ""
Dim strLinkColor	        :	strLinkColor = ""
Dim strHeadingColor         :   strHeadingColor = ""
Dim strRHTextColor          :   strRHTextColor = ""
Dim strLineColor            :   strLineColor = ""
Dim strSeparatorBarColor    :   strSeparatorBarColor = ""
Dim strImageNumber          :   strImageNumber = ""
Dim strMenuImage            :   strMenuImage = ""

Dim strLightTextColor       :   strLightTextColor = "FFFFFF"
'Dim intBaseFontSize	    :	intBaseFontSize = 11
Dim intBaseFontSize	        :	intBaseFontSize = 2.75

If Len(Trim(Request.QueryString("d"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("m"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("l"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("c"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("link"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("f"))) > 2 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("h"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("r"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("line"))) <> 6 Then Response.Redirect "/error.asp" End If
If Len(Trim(Request.QueryString("sb"))) <> 6 Then Response.Redirect "/error.asp" End If

strDarkColor = Trim(Request.QueryString("d"))
strMediumColor = Trim(Request.QueryString("m"))
strLightColor = Trim(Request.QueryString("l"))
strContrastColor = Trim(Request.QueryString("c"))
strLinkColor = Trim(Request.QueryString("link"))
strHeadingColor = Trim(Request.QueryString("h"))
strRHTextColor = Trim(Request.QueryString("r"))
strLineColor = Trim(Request.QueryString("line"))
strSeparatorBarColor = Trim(Request.QueryString("sb"))
strImageNumber = Trim(Request.Querystring("in"))
strMenuImage = Trim(Request.Querystring("mi"))

If strMenuImage = "" Then strMenuImage = "bg_1" End If
If strImageNumber = "" Then strImageNumber = "1" End If

If Trim(Request.QueryString("f")) <> "" and IsNumeric(Trim(Request.QueryString("f"))) then
	intBaseFontSize = CInt(Trim(Request.QueryString("f")))
    If intBaseFontSize < 16 Then intBaseFontSize = 15 End If
    intBaseFontSize = intBaseFontSize / 16
End If

%>

Modified by cor-el

more options

The top part looks fine. When you get to the actual output of the page, are you setting Response.ContentType to text/html, or adding an inconsistent content type using Response.AddHeader?

more options

Please forgive me here...not sure I understand your question, but I'm going to stab at answering.

We build the page using a lot of functions. So my actual page is put together like this:

<% ASP code to do various things %> <title>liveandworkwell.com</title> <% buildHead() %> ***this is where the stylesheet is linked in***' Is the problem that when I'm adding in the ContentType = "text/css" I'm not switching back to ContentType = "text/html" when I get back out of the stylesheet?

more options

Your page uses a <link> tag to incorporate the style sheet. Therefore, Firefox makes a separate request for styles.asp and it is retrieved independently as a completely separate page. So... no, you aren't doing anything in the main page that is causing this problem. styles.asp is being served with a content-type of text/html, which needs to be changed to text/css in that file itself.

Here's a simple example of the header changing the content type:
demo: http://dev.jeffersonscher.com/asp/content-type-css.asp
code: http://dev.jeffersonscher.com/asp/content-type-css.txt

Since you've done that, I'm not sure why it isn't sticking; are there any caches you might need to flush on the server?

more options

I will look at these examples and do a restart of the server and test again. Thanks, again, so much for the help! I'll let you know how it goes =)

more options

Your example made it so clear...thank you!!! I had it way too high in the code on the styles.asp page...once I moved it down just above the actual CSS code, bingo!

I think I luv you a little bit =) thanks again!!