473,387 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

External stylesheet setting in Firefox

Hello. I am in the process of modifying some JavaScript code which
refers to an external stylesheet, but unfortunately I have very little
previous JavaScript experience. Currently the code has only been
written to be used in IE but I am looking into getting it to work for
Firefox. I have addeda small piece of code to detect Firefox and then
wish to reset the stylesheet from the IE version to a Firefox version.
Unfortunately the same line of code which works in IE does not work in
Firefox:

document.styleSheets[0].href = "styles/FIREFOX/" + stylesheet;

which gives the following error in the debugger:

Error: setting a property that has only a getter

This is quite a vague error and I cannot figure out an alternative. As
I understand it, the href property is read-only in Firefox so is there
some other method I can use instead?

Thanks in advance.

Oct 6 '06 #1
4 2100

Barry ha scritto:
document.styleSheets[0].href = "styles/FIREFOX/" + stylesheet;
Error: setting a property that has only a getter
in W3c/Firefox that is only a read-only property but
you can dinamically change the href as follow:

i.e.

your style:
<link id ="my_style" rel="stylesheet" type="text/css"
href="../css/ui_controls.css"/>

your function:
function changeStyle(css)
{
var l = document.getElementById("my_style");
l.href = css;
}

than with an event pass your css url file to that function:
<input type="button" value="change style"
onclick="changeStyle('other.css')"/>

Bye

Oct 6 '06 #2
Worked a treat - many thanks.

Oct 6 '06 #3
If you have multiple stylesheets like this:

<link rel="stylesheet" href="one.css">
<link rel="stylesheet" href="two.css">
<link rel="stylesheet" href="three.css">

you can activate them in javascript with

document.styleSheets[i].disabled = true;

Oct 6 '06 #4
I mean:
.....disabled = false;

vynogra...@gmail.com wrote:
If you have multiple stylesheets like this:

<link rel="stylesheet" href="one.css">
<link rel="stylesheet" href="two.css">
<link rel="stylesheet" href="three.css">

you can activate them in javascript with

document.styleSheets[i].disabled = true;
Oct 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christopher Benson-Manica | last post by:
Just FMI, if an external stylesheet is linked to a page (with <link>), will subsequent <style> tags override the values in the external stylesheet? -- Christopher Benson-Manica | I *should*...
12
by: Tony Carnell | last post by:
Hi, Here's a conundrum that I hope someone out there can help me solve. I've created a page to XHTML 1.0 Transitional / CSS standards using Macromedia Dreamweaver MX 2004 (and validated both...
5
by: David Trimboli | last post by:
I'm writing HTML 4.01 and CSS 2 pages that include a CSS-driven pop-up menu. What I'm trying to do is create a screen style that uses the menu, links, etc. normally, and a print style that removes...
14
by: David Blickstein | last post by:
I have some XML documents that I want to open in a web browser and be automatically translated to HTML via XSLT. I'm using an xml-stylesheet processing command in a file called "girml.xml". ...
17
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script...
3
by: gdelfino | last post by:
I have an XML file which I transform into XHTML using stylesheetA.xsl. I also have stylesheetB.xsl which transforms my XML file into an Excel XML document. As both Excel and most new browsers...
11
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css">...
6
by: chris.rapking | last post by:
This seemingly happened overnight. http://www.chrisrapking.com The styles that are inline work fine. Anything in the head does not (which, if you notice, includes some styling information plus...
4
by: th1421 | last post by:
Hi, I'm new to FireFox. I am currently trying to convert my website to be compatible with it. Doing so I’m trying to process some XML/XSLT pages (preferably without using JavaScript). When I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.