Forever Zero
06-17-2008, 04:50 PM
Hello,
I am working on a project (a Firefox extension if it matters), which basically highlights words on the page that a user enters via a text box. To do this, I need to apply an outside style sheet to the page, or insert my style sheet directly into the existing website.
The two things that I have tried so far:
First, I tried this:
var head = document.getElementsByTagName('head')[0];
var styleString = "<link rel=\"stylesheet\" href=\"highlight.css\" type=\"text/css\"/>";
head.innerHTML = head.innerHTML + styleString;
This made my JavaScript not execute at all (I didn't get any errors in the error console that seemed to be related, so I'm still not sure why this didn't work).
After that, I tried to inject the style rules directly into the browser like this:
var CSS = "
.tools {
margin-left: auto;
margin-right: auto;
width: 100%;
text-align: center;
padding-bottom: 20px;
border-bottom: 4px solid;
}
... Insert the rest of the really long style sheet here ...
";
document.styleSheets[0].insertRule(CSS,0);
This did not work either.
Any idea on this would be much appreciated! Thanks :)
I am working on a project (a Firefox extension if it matters), which basically highlights words on the page that a user enters via a text box. To do this, I need to apply an outside style sheet to the page, or insert my style sheet directly into the existing website.
The two things that I have tried so far:
First, I tried this:
var head = document.getElementsByTagName('head')[0];
var styleString = "<link rel=\"stylesheet\" href=\"highlight.css\" type=\"text/css\"/>";
head.innerHTML = head.innerHTML + styleString;
This made my JavaScript not execute at all (I didn't get any errors in the error console that seemed to be related, so I'm still not sure why this didn't work).
After that, I tried to inject the style rules directly into the browser like this:
var CSS = "
.tools {
margin-left: auto;
margin-right: auto;
width: 100%;
text-align: center;
padding-bottom: 20px;
border-bottom: 4px solid;
}
... Insert the rest of the really long style sheet here ...
";
document.styleSheets[0].insertRule(CSS,0);
This did not work either.
Any idea on this would be much appreciated! Thanks :)