PDA

View Full Version : Enabling/disabling style sheets remotely..... how to do it?


jeffery1493
11-06-2009, 09:56 PM
Hi all,

The standard method for enabling (showing) and disabling (hiding) a css style sheet is this:


document.styleSheets[0].disabled=true;


This method is used to change background pictures on a web page to other ones, say, if a user clicks a button or selects a drop-down option.
You can have two css files with two different pictures, styleSheets[0] and styleSheets[1], and hide and swap them to make the picture change.

However, "document" always refers to the current window you are in. If a web page has multiple windows (controlled by different css files), does anyone know how to disable the stylesheet of a Different window than the one you are in?

For example:

[the other window on the page].document.stylesheets[0].disabled=true??

? ? ? ? ?

That way, you can click a button or change the drop down on one window, and have it affect the PICTURE in the other window.

I've been stuck on this for days.
Thanks for any help!

gsnedders
11-07-2009, 12:10 PM
What do you mean by multiple windows? Are you using frames/iframes? If you are, and the frame/iframe is on the same domain and subdomain as you, then you can do something like:


window[0].document.stylehseets[0].disabled = true;


That'll get the first frame/iframe on the page and disable the first stylesheet in that.

jeffery1493
11-08-2009, 04:26 AM
When I use (to test):

<a href="javascript:
window[0].document.styleSheets[0].disabled=true;
window[0].document.styleSheets[1].disabled=true;
window[0].document.styleSheets[2].disabled=true;
window[0].document.styleSheets[3].disabled=true;
window[0].parent.Refresh();
">CLOSE THE WINDOWS</a>

From the other window, I get a JavaScript error:

Error: 'window.0.document' is null or not an object

? ? ?

and yes they're on the same subdomain and domain, the two css files are even in the same directory.

gsnedders
11-08-2009, 10:46 PM
What do you mean by other windows? It's not entirely clear what you're trying to do. Like, where is this other window? How is it created?