This is a discussion on "Externalising Javascript" within the JavaScript Forum section. This forum, and the thread "Externalising Javascript are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Externalising Javascript
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Externalising Javascript
Hello
Could anybody give me a step by step (idiots) guide on how to externalise Javascript (ie, make it like you're talking to a 10 year old.. !). I've read posts, looked at articles on the net and I don't want to bodge my site up having done that once already! Cheers |
|
|
|
|||
|
Re: Externalising Javascript
Hi pickle right step by step
First of highlight the JavaScript code out the whole section so E.g. <Script> <!-- function sf(){document.f.q.focus();} function rwt(el,ct,cd,sg){el.href="/url?sa=t&ct="+escape(ct)+"&cd="+escape(cd)+"&url=" +escape(el.href).replace(/\+/g,"%2B")+"&ei=IkXGQ-rJB8rARfOviYEI"+sg;el.onmousedown="";return true;} // --> </script> then create a new file and paste it in make sure if you are using macromedia you create a new JavaScript file then paste in there take out the script tags so remove <script> </script> then save this as (whatever.js)just an example. Then go back into your code and were the JavaScript was paste this code there <script language="JavaScript" src="whatever.js"></script> The bit highlighted in green change to the name that you saved the JavaScript as. Then it should work. Hope this helps |
|
|||
|
Re: Externalising Javascript
Perfect
Thank you so much! |
|
|||
|
Re: Externalising Javascript
no worrys any other things i can help you with
|
|
|||
|
Re: Externalising Javascript
Hello
Just doing this now, seems quite straightforward but do I need to use a new file for each piece of javascript? Also, this is an example of some script: <script language="JavaScript" type="text/JavaScript"> <!-- function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> when I paste this into the script.js file (or whatever I call it) do I delete the line <script language="JavaScript" type="text/JavaScript"> and then </script>? Many thanks |
|
||||
|
Re: Externalising Javascript
yes, u do delete those lines, and you can put as much javascript as u like in one file
|
|
|||
|
Re: Externalising Javascript
Hi is this the same for externalising php code as well.
(ive got an invisible php counter but i don't want to change the page to .php just for this tiny code thats about 4 lines long) |
![]() |
| Tags |
| externalising, javascript |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what does + + mean in Javascript eg: var m = (A1+ +B4); | Andy K | JavaScript Forum | 6 | Dec 13th, 2006 23:57 |
| using xml in javascript | shailu | JavaScript Forum | 0 | Jul 25th, 2006 07:36 |
| Externalising Javascript | Pickle | JavaScript Forum | 3 | Feb 7th, 2006 20:20 |
| what does \\ mean in javascript | jenjen1018 | JavaScript Forum | 5 | Jan 6th, 2004 17:05 |