tags:

views:

928

answers:

2

Hi,

I have a function that is mean to alter the font-size:

// change the font size of the document
function changeSize(fontSize) {
    var sheets = document.styleSheets; // Array of all stylesheets

    for(var i=0; i < sheets.length; i++) { // For each stylesheet
        var sheet = sheets[i];

        // alert( sheets[i].title );

        if(sheet.title == 'textSize') { // find the one called 'textSize'
            // alert( "hello!" );
            var rules = sheet.cssRules || sheet.rules; // Array of rules
            var rule = rules[0]; // The first rule

            // Should only be one rule, and it should be a one line font-size declaration
            if(rules.length == 1 && rule.selectorText.match(/body/i) && rule.style.fontSize) {
                rule.style.fontSize = fontSize;
                return true;
            }
            else return false; // This is a bad stylesheet, return false
        }
    }

    return false; // Haven't found the stylesheet - return false
    }

This works if the stylesheet it looks for is in the same directory as the page the function is located in but if it is in a separate directory - e.g. ../js/js.js instead of ./js.js - it throws the following error:

Security error" code: "1000

Any idea how I resolve this? I don't know much about javascript and I'm hoping it's not a case of simply "NOT ALLOWED" but if so what are the sensible alternatives?

Thanks

+1  A: 

Error 1000 usually means you are trying to change something in the DOM which is not allowed. It seems that you only manipulate Stylesheets in the same directory as the Page - so it is probably a security issue. How are the CSS files in question reference - absolute paths, relative paths?

Paul Lydon
I tried relative and abolsute.
Adam Taylor
A: 

Attention:

Security error" code: "1000 is also caused by Skype extension for Firefox. I do not know if there are Skype addons for other browsers but we know for sure that Skype extension for Firefox is causing a lot of problems especially in sites that use JavaScript to dynamically change styles.

Sorry for english.

Sebastian