Dynamically add <link> or <script> to page <head>

I am a designer working on some .asp pages.  On some pages I don't have access to the <head> tag.  I want to be able to insert/append either a <link>, <script> or both into the <head> of the page from an include file that is included into the page somewhere in the HTML.

Is this possible?  If so can someone show me how to go about doing just that with an asp tag or function?

Thanks
lightrayzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:

<script>
function importFile(url,type){
  var node=null;
  if(String(type).toLowerCase()=='js')
  {
     node=document.createElement('script');
     node.type='text/javascript';
     node.src=url;
  }
  else if(String(type).toLowerCase()=='css')
  {
      node=document.createElement('link');
      node.type='text/css';
      node.rel='stylesheet';
      node.href=url;
  }
  var head = document.getElementsByTagName('head')[0];
  head.appendChild(node);
}

importFile('styles.css','css');
importFile('yourPlugin.js','js');
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mattibuttCommented:
hi
some of the script doesnt need to be in the head section of the page if you are using or your team is using asp then the clever way should be like having just one header file it will save time and efforts
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.