Dynamically Including JavaScript and CSS Files

<script language=“javascript” type=“text/javascript”>
function includeJS(src) {
if(document.createElement && document.getElementsByTagName) {
var headtag = document.getElementsByTagName(“head”)[0];
var newjs = document.createElement(“script”);
newjs.setAttribute(“type”, “text/javascript”);
newjs.setAttribute(“language”, “javascript”);
newjs.setAttribute(“src”, src);

headtag.appendChild(newjs);
}
}
function includeCSS(link) {
if(document.createElement && document.getElementsByTagName) {
var headtag = document.getElementsByTagName(“head”)[0];
var newcss = document.createElement(“link”);
newcss.setAttribute(“rel”, “stylesheet”);
newcss.setAttribute(“type”, “text/css”);
newcss.setAttribute(“href”, link);

headtag.appendChild(newcss);
}
}
function change() {
includeCSS(http://domainname.com/selvam/testcss.css&#8221;);
includeJS(http://domainname.com/selvam/testjs.js&#8221;);
}
</script>
<h1>Test H1</h1> <input type=“button” name=“cmd_button” id=“btn” value=” change screen” onclick=“change();”>

About selvam4win

I am Selvam. I am very jolly person and frank one.

Posted on December 22, 2010, in Dynamic CSS, Dynamic Javascript, javascript and tagged , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: