Access a frame's styleSheets object?
Posted: Wed Apr 30, 2008 9:01 am
The following script was written mostly by me though critical parts should be credited to Mark Wilton-Jones.
Any way it works perfectly fine except that I'd like to add support for frames. I know that in general you access a frame via parent.frame_name. I however am not sure how to access a frame's document.styleSheets object.
I can work the if frame/no frame if/else in, I just need to know where and how to apply it?
Any way it works perfectly fine except that I'd like to add support for frames. I know that in general you access a frame via parent.frame_name. I however am not sure how to access a frame's document.styleSheets object.
I can work the if frame/no frame if/else in, I just need to know where and how to apply it?
Code: Select all
function change_rule(selector,property,value){var css_file_name = 'style';if (document.styleSheets){for (var oSsDmCt = 0; oSsDmCt < document.styleSheets.length; oSsDmCt++){if (document.styleSheets[oSsDmCt].href.indexOf(css_file_name) + 1)// || document.styleSheets[oSsDmCt].href.indexOf('style-broadband-images.css') + 1){var oStyleSheet;oStyleSheet = document.styleSheets[oSsDmCt]; break;}}if (!oStyleSheet) {oStyleSheet = document.styleSheets[document.styleSheets.length-1];}}if (document.getElementById('coloreditor')){var selector = document.forms['coloreditor'].step_one.value;var property = document.forms['coloreditor'].step_two.value;var value = '1';if (property == 'background-color') {if (document.forms['coloreditor'].step_three_1.value != 'transparent') {var value = '#' + document.forms['coloreditor'].step_three_1.value;} else {var value = document.forms['coloreditor'].step_three_1.value;}}else if (property == 'background-image') {if (document.forms['coloreditor'].step_three_1.value != 'transparent') {var value = 'url(\''+path+ 'themes/general/background-'+document.forms['coloreditor'].step_three_2.value+'.gif\')';}else {var value = 'none';}}else if (property == 'border-color') {if (document.forms['coloreditor'].step_three_3.value != 'transparent') {var value = '#' + document.forms['coloreditor'].step_three_3.value;} else {var value = document.forms['coloreditor'].step_three_3.value;}}else if (property == 'color') {if (document.forms['coloreditor'].step_three_4.value != 'transparent') {var value = '#' + document.forms['coloreditor'].step_three_4.value;} else {var value = document.forms['coloreditor'].step_three_4.value;}}}var new_rule = selector + ' {' + property + ':' + value + ';}'; oStyleSheet.insertRule(new_rule,oStyleSheet.cssRules.length);window.hasAddedNewRule = true;}