Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Storing alternate stylesheet name in cookie

29 views
Skip to first unread message

Peter X

unread,
Sep 30, 2003, 11:18:52 PM9/30/03
to
Hi all,

I'm just about to implement an alternate stylesheet along with
JavaScript to store the stylesheet title in a cookie.

However, it doesn't seem to be working in Opera 7.20 for Windows!

The problem as far as I can tell is that if I use the View->Style menu
to select a new style, then code on the window.unload event is meant to
find the currently active stylesheet by checking the "disabled"
attribute. It appears that Opera is failing to change this.

I'm basically using the same code as: http://meyerweb.com/

Is this a regression?

Thanks in advance!

Peter.

Andrew Gregory

unread,
Oct 2, 2003, 1:50:27 AM10/2/03
to
On Wed, 01 Oct 2003 04:18:52 +0100, Peter X <pete...@hotmail.com> wrote:

> I'm just about to implement an alternate stylesheet along with
> JavaScript to store the stylesheet title in a cookie.

Try using the technique described on A List Apart:

<URL:http://www.alistapart.com/stories/alternate/>

I'm using it and it seems to work very well. Easy too!
--
Andrew Gregory
<URL:http://www.scss.com.au/family/andrew/>

Peter X

unread,
Oct 2, 2003, 9:33:44 AM10/2/03
to
Andrew Gregory wrote:
> On Wed, 01 Oct 2003 04:18:52 +0100, Peter X <pete...@hotmail.com> wrote:
>
>> I'm just about to implement an alternate stylesheet along with
>> JavaScript to store the stylesheet title in a cookie.
>
>
> Try using the technique described on A List Apart:
>
> <URL:http://www.alistapart.com/stories/alternate/>
>
> I'm using it and it seems to work very well. Easy too!

I am!! And the one that Eric Meyer is using at:

http://meyerweb.com/

is the same and it doesn't appear to be working. As I say, I *think*
this might be a problem in 7.20 (Windows).
It could just be my installation however?

Another site that doesn't seem to work correctly is:

http://www.zeldman.com/

Which (although I haven't checked the code myself) is using the Paul
Sowden/ALA code.

What I'm finding is that the cookie is *not* being written out
containing the stylesheet title. The reason (as far as I can assertain)
is that the JavaScript looks for the LINK with @rel="Alternate
Stylesheet" that has .disabled=false (i.e. it is enabled).

Problem is, when I select an alternate style *via the Opera menu*, so I
click View->Style->what-ever, the "disabled" property is not being set
correctly. So the JavaScript doesn't know what alternate stylesheet has
been selected.


Thanks for you reply!!

Peter.

Andrew Gregory

unread,
Oct 3, 2003, 2:14:15 AM10/3/03
to
On Thu, 02 Oct 2003 14:33:44 +0100, Peter X <pete...@hotmail.com> wrote:

> Problem is, when I select an alternate style *via the Opera menu*, so I
> click View->Style->what-ever, the "disabled" property is not being set
> correctly. So the JavaScript doesn't know what alternate stylesheet has
> been selected.

Ah, I see. That doesn't work for me either. You have to use the provided
code to select the different style sheets.

I'd be surprised if link elements had a disabled property defined. The w3c
dom spec should have something to say about that, but I haven't checked.

Peter X

unread,
Oct 3, 2003, 4:50:04 PM10/3/03
to
Andrew Gregory wrote:

I had a quick check at W3C and I can't see a "disabled" property on the
"link" element. But if it is non-standard, then why/how does Opera work
when the stylesheet is set via the setActiveStyleSheet function?

This function just sets the "disabled" property of the link element to
true, so if Opera isn't using this then it shouldn't work!!


I did find a disabled property on the styleSheet object in DOM, e.g.
"document.styleSheets[n].disabled = true" would enable stylesheet *n*.

So I re-coded the getActiveStyleSheet function:

function getActiveStyleSheet() {
var i, ss;
for(i=0; i < document.styleSheets.length; i++) {
ss = document.styleSheets[i];
if(!ss.disabled
&& ss.ownerNode.getAttribute("rel").indexOf("style")!=-1
&& ss.ownerNode.getAttribute("title")
) return ss.ownerNode.getAttribute("title");
}
}

...but then I discovered that Opera doesn't support
document.styleSheets[] !!

I'm still googling around to try to find a solution but if anyone has
any ideas I'd be grateful!!

Best regards,

Peter.

Peter X

unread,
Oct 3, 2003, 6:29:06 PM10/3/03
to
Peter X wrote:

Opera support for DOM level 2 isn't looking so good:

http://www.w3.org/2003/02/06-dom-support.html

I'll query this in the opera.tech group!

0 new messages