views:

194

answers:

1

I am using a phpbb3 forum with a bbcode to insert an iframe. I want to use the css from the forum for the iframe. I tried some code I found here but it isn't working. I might be doing something wrong but I'd love to get this working, especially since users can change the forum css. The forum is: botdls.prophbb.com and the iframe is the "shoutbox" at the top. Thanks. Here is the code I used from this site which I found from google.

var cssLink = document.createElement("link") 
            cssLink.href = "pFstylesEditor.css"; 
            cssLink .rel = "stylesheet"; 
            cssLink .type = "text/css"; 

            //Instead of this
            //frames['frame1'].document.body.appendChild(cssLink);
            //Do this

            var doc=document.getElementById("edit").contentWindow.document 

            ///If you are doing any dynamic writing do that first
            doc.open;
            doc.write(myData);
            doc.close();

            //Then append child
            doc.body.appendChild(cssLink);
A: 

I spotted one problem right away. You're creating an element in the parent document and trying to append it to the child document - this won't work. You need to create the element using the child frame's document instead:

var doc=document.getElementById("edit").contentWindow.document;

var cssLink = doc.createElement("link");
cssLink.href = "pFstylesEditor.css";  
cssLink.rel = "stylesheet";  
cssLink.type = "text/css";  

///If you are doing any dynamic writing do that first 
doc.open();        // <-- you also missed the parenthesis here
doc.write(myData); 
doc.close(); 

//Then append child 
doc.body.appendChild(cssLink); 

Also, open is a method and you missed off the parenthesis (open()).

Andy E
I just pulled this off another post here. How can I figure out the ElementID? Firebug lists them all separately. I tried what I thought the element id is but I just want to make sure that's not my mistake. Also, pFstylesEditor.css should be changed to the actual link of the css stylesheet or is that a naming convention like with prototype or jQuery?
Michael Gomez