Forum Moderators: open

Message Too Old, No Replies

Stylesheet switching headaches

         

doodlebee

4:14 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Hey all - I was hoping someone here could help me out. I'm being forced to use ASP - a language which I know pretty much nothing about. Amazingly, so far, I've done okay - but I could cry at the hackish attempts I've made at this. So I'm begging someone to help me.

Basically, I'm coding a site that requires the use of a stylesheet switcher. The client in question is targeting the elderly, and wants a button at the top of each page that says "Enlarge Text". The idea is, when you click that button, the whole site enlarges the font quite a bit. Now normally you can do this by simply using the toolbar in your browser and enlarging the text, but the client insists on having this button. Now I can do this easily in PHP - but ASP is making me wish I could crawl into a hole and die. :)

I finally found a way to make this work (and by god, I even got it to swap out my conditional comments at the same time!) but now I have 2 new issues I cannot seem to get around, and if anyone can help me, I would be forever in your debt.

First, here is the index page to the site. It's basically a small script that - from my understanding - "turns on" the stylesheet swapping capability and reads whether or not a cookie has been set. The script also immediately redirects the end user to the actual page of the site - it just needs to go through this bitty script first (something about headers being sent before the script would mess it all up if I didn't do it this way):


<%
Dim strNewStyle
strNewStyle = Request.QueryString("style")

If Len(strNewStyle) > 1 Then
Response.Cookies("stylesheet") = strNewStyle
Response.Cookies("stylesheet").Expires = Date + 30

End If

Response.Redirect ("home.asp")
%>

As you can see, it'll redirect you to "home.asp" - no problem. Now, in the header of my "home.asp" document, I have this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="copyright" content="Copyright 2005" />
<meta name="author" content="" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />

<%
Dim strCurrStyle
strCurrStyle = Request.Cookies("stylesheet")

If strCurrStyle = "" Then
strCurrStyle = "main"

Else
Response.Cookies("stylesheet").Expires = Date + 30
End If
%>

<link rel="stylesheet" href="http://www.site.com/css/<%= strCurrStyle %>.css" />

<!--[if IE 6]>
<link rel="stylesheet" href="http://www.site.com/css/<%= strCurrStyle %>_ie.css" />
<![endif]-->

<!--[if IE 5.5000]>
<link rel="stylesheet" href="http://www.site.com/css/<%= strCurrStyle %>_ie55.css" />
<![endif]-->

<!--[if IE 5]>
<link rel="stylesheet" href="http://www.site.com/css/<%= strCurrStyle %>_ie5.css" />
<![endif]-->

<style type="text/css">
/*\*//*/
@import "http://www.site.com/css/<%= strCurrStyle %>_ie5mac.css";
/**/
</style>

</head>

Now, as you can see, the "further" scripting up there says the prefic for the default stylesheets is "main" (so you end up with "main.css", "main_ie.css", "main_ie55.css" and so on so that all my conditional comment stylesheets will be changed on the one click of the button.) When the button is clicked, thus changing the stylesheet, all references of "main" will be changed to "larger".

Cool. Works great. Except - as I said - for two things:

1) I *know* this is a server-side script, and should NOT be affected by whatever browser you are using. *Except* for some reason, I am being affected. This works great in all browsers I have *except* IE 5.5 and IE 5.01 for PC. For some reason, those two browsers *are not* accepting the change from "main" to "larger" no matter what I do. I don't know why it's doing this, and I know it *shouldn't* be doing this, but it is - would anyone have any ideas as to why?

and...2) When you're surfing through the site, the cookie is definitely working. You click that button on one page, and the whole site will get bigger. However, if you are on an inside page of the site and clieck the button, it'll make the site bigger *and* return you to the index page of the site. I know it's because of this line:


Response.Redirect ("home.asp")

Is there any ASP coding or something I can replace that "home.asp" with so that it recognizes it's on a different page/automatically put the page's filename in that spot? Or will I have to go through the entire site, page-by-page, and change that "home.asp" to the name of the actual page you're on? (I'm hoping there's a more relative way to do this rather than go through each individual page and changing it!)

I'd really appreciate any help/ideas you all may have. Thanks so much!

paulanthony

5:25 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



First of all...theres already lots of pre rolled options out there.

[google.co.uk...]

The conditional comments are affecting the different browsers....these were only introduced in later browsers..so that is probably affecting things.

As for determining what page you are on...

<% Request.Servervariables("URL") %> might help...in fact take a look at

[4guysfromrolla.com...] for more info on the request object. You probably need to pass in the page you are on to the default page, so it can redirect to correct page.

e.g

Dim strPageImon
strPageImon = Request.Servervariable("URL")

<% Response.Write("<a href=change_size.asp?page" & strPageImon & "") %>

something like that.

doodlebee

8:27 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



First of all...theres already lots of pre rolled options out there.

[google.co.uk...]

Actually the first one that shows up on that search list is the one I'm using :) I had to edit it a bit to get the conditional comments to work.

The conditional comments are affecting the different browsers....these were only introduced in later browsers..so that is probably affecting things.

But I'm wondering *how*. When I use the conditional comments as I normally would (no asp) they work just fine. The only thing that's changed is the ASP changes the name of the file from "main" to "larger". In all other browsers, there's no issue with the name change. After you click the button, you can view the source code and the name has changed and the site calls in the alternate stylesheet. But for some reason, IE 5 will *not* accept the name change. I'm utterly at a loss as to why it won't do this, when it's a server side thing. it just makes no sense to me.

You know, I'm going to chalk it up to some setting in *my* browser (that I'm going to need to find) because I've asked a couple of other people to look, and they have no problem. The switcher is working for them - but for some reason, I can't see the switch. It's goota be something wrong with *my* browser. It's so weird.

As for determining what page you are on...

Thank you! I'll give this a try - I really appreciate it.