hello guys, i have a javascript code which look like that <script type="text/javascript" src="http://paypopup.com/code.js?id=3133"></script> Code (markup): its a code for popup ads i have to add it in every webpage... i'm trying to add this code in a separate which i call it myscript.js and i want to link to it from all the site pages using the following code <script type="text/javascript" src="myscript.js"></script> Code (markup): is that possible to happen?????
There are two ways of handling it... the first is, well... sloppy and old -- using document.write to add it in the page during load... Really that method belongs in the past. The modern way is to manipulate the DOM. var newElement=document.createElement('script'); newElement.setAttribute('type','text/javascript'); newElement.setAttribute('src','pathto/yourscript.js'); var docHead=document.getElementsByTagName('head')[0]; docHead.appendChild(newElement); Code (markup): The same method can be used to load CSS from javascript-- createElement('link'), and be sure to set the proper TYPE, REL and MEDIA values. Note that functions and code from that script may not be available until the script you call it in ends/breaks for a bit.