One task this has required is the insertion of a new CSS file into the page. My project structure displays all content inside of a single PHP file based on URL parameters. Therefore, when individual pages require special CSS, I need to make that happen within the page, not in the wrapper, to avoid unnecessary bandwidth usage.
Here is some Javascript that will load a CSS file into the page's header when called in the body:
<script type="text/javascript">
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "thedir/thefile.css");
document.getElementsByTagName("head")[0].appendChild(fileref);
</script>
No comments:
Post a Comment