Click to See Complete Forum and Search --> : Style tag read only problem
cyrrhose
09-15-2003, 02:33 AM
Hello!
I'd like to remove in a html page the <style> tag and add to the page a new style sheet.
For adding the style sheet I use document.createStyleSheet(...); but the problem is when I first try to remove the <style> tag, because the method getELementByTagName("style") gives a read-only access to the tag and leads to an error when I call .innerHTML="". Are the other possible ways to remove this style tag?
Thanks in advance!
Cyril
cyrrhose
09-15-2003, 05:21 AM
Now I'm using an other way, but I get the same execution problem
"Unspecified error, code 0" just after removeNode() method call.
top.centerFrame.frames[0].document.designMode="On";
var oStyles=top.centerFrame.frames[0].document.getElementsByTagName("STYLE");
if (oStyles!=null && oStyles.length>0){
oStyles[0].removeNode(true);
}
top.centerFrame.frames[0].document.recalc(true);
top.centerFrame.frames[0].document.createStyleSheet("/metaread/styles/ISIView.css");
top.centerFrame.frames[0].document.recalc(true);
Could someone please help me out?
Swapping CSS is the general method used, see this article (http://www.alistapart.com/stories/alternate/)
cyrrhose
09-15-2003, 07:19 AM
Thanks for the article, it will be very usefull to solve other problems I have to face. The problem is in fact that I don't have any control on the html page that I display; I can just add a style sheet with javascript, but html coded styles override all the styles I try to control with this style sheet.
The original file has styles defined in the header with the <style> tag, and the easiest way for me to control all fonts is to get rid of this style tag and then add my stylesheet.
But I encounter the above given error, and I think even if this worked, I think that my style sheet will always be overriden by tags as [code]<span lang=EN-GB
style='font-size:12.0pt;mso-bidi-font-size:10.0pt;mso-ansi-language:EN-GB'> [code] as we can encounter in the original file.
Do you know a way to force the hole page to be displayed according to the css file?
Once you have added you new style sheet, I think you have to swap the CSS.
You could remove (http://javaalmanac.com/egs/org.w3c.dom/RemNode.html) the CSS, but the new CSS will not automatically become active.
Give it a try!
cyrrhose
09-16-2003, 04:38 AM
Thanks! but I'll have to do this with jsp?
OK, I'll adapt this to javascript. Thanks for the tip!