PDA

View Full Version : Resolved Stylesheet Switcher Browser and Cookie issues



printman55
05-25-2010, 03:45 PM
1) Script Title: Style Sheet Switcher (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm

3) Describe problem: I went ahead and set up a simple two page site to test the earlier question on keeping the initial randomly selected stylesheet consistent through out the site. The link is http://www.rspsitedesign.com/Random/ Here is what is weird in Firefox: First I cleared out cache and then disabled all cookies. It starts out with the default style sheet, and toggles back and forth between home and inside page. On about the third toggle it shifts to and alternative stylesheet. So it is not consistent. If cookies are enabled it seems to work ok.
In Internet Explorer if privacy is set to high, the random selection is inconsistent similar to Firefox. If cookie privacy is set to medium the random selection seems to work ok.
Is there a way to test for browser privacy levels and if the are allowed then use the random selection. If not, then use the default style sheet?

There is also a delay in the page transfer which is unusual given the simplicity of the pages.

ddadmin
05-25-2010, 10:25 PM
The script relies on cookies to store the style settings, so if you disable cookies in the browser, it's to be expected that the styles will no longer be properly recalled.


Is there a way to test for browser privacy levels and if the are allowed then use the random selection. If not, then use the default style sheet?

You can try checking whether or not cookies are enabled on the user's browser, and if not, skip the changing of styles by the script. Try the below modified .js file.

printman55
05-26-2010, 12:29 AM
Thanks for the code. I uploaded the new styleswitch.js file and with cookies enabled the only stylesheet that applies is the default.css. This ocurrs in both IE and Firefox.
http://www.rspsitedesign.com/Random/index.html
In IE there is also an error code as follows:
Message: 'return' statement outside of function
Line: 69
Char: 1
Code: 0
URI: http://www.rspsitedesign.com/Random/styleswitch.js

printman55
05-26-2010, 03:24 PM
I reset the two variables in the .js file:
var manual_or_random="random" //"manual" or "random"
var randomsetting="sessiononly" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
Now with cookies enabled or disabled it defaults to default.css in both IE and Firefox.
Also in IE still getting the line 69 error above.

ddadmin
05-26-2010, 11:01 PM
Ah yes there is an error in the modified .js file I posted. Try the below version instead.

printman55
05-27-2010, 01:59 AM
I tried it still no change. I reset the code lines:
var manual_or_random="random" //"manual" or "random"
var randomsetting="sessiononly" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
Plus still getting the line 69 error in IE.

ddadmin
05-27-2010, 06:57 AM
You shouldn't be getting any errors any more at least (I just tested it again). Do you have a link to the problem page?

printman55
05-27-2010, 10:43 AM
Here is the link to the page:
http://www.rspsitedesign.com/Random/index.html It now appears to be working properly!!!
Yea!!! Cookies or no cookies works as planed. When cookies disallowed it reverts to the default.css. The error has gone away. I must have made an error in the way the revised js file was uploaded because I did it again and now it works. There is still a little more time delay in the toggling between inside and homepages though.

printman55
05-28-2010, 02:49 AM
Were you able to see why there is a delay in navigating between the two pages??

ddadmin
05-28-2010, 08:38 AM
Are you sure the delay is due to the script, and not perhaps just your server reacting a bit sluggishly? I tried viewing your the test link with JS disabled and still get the 1-2 second delay between page loads.

printman55
05-28-2010, 10:48 AM
I tried it on several other servers and same thing. It sort of happens on about the third round of toggling. I would guess it is the browser updating page and cookie cache. I went a step further and took out the js file and used the default.css.
http://www.rspsitedesign.com/Random/index2.html
Does the same thing. So I agree it's not the code, not the server, I guess browser thing.