Externalising Javascript

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 12th, 2006, 10:50
Junior Member
Join Date: Dec 2005
Location: Leeds
Age: 35
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote

  #2 (permalink)  
Old Jan 12th, 2006, 11:08
New Member
Join Date: Jan 2006
Location: thorpe le soken
Age: 22
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #3 (permalink)  
Old Jan 12th, 2006, 21:14
Junior Member
Join Date: Dec 2005
Location: Leeds
Age: 35
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Externalising Javascript

Perfect

Thank you so much!
Reply With Quote
  #4 (permalink)  
Old Jan 13th, 2006, 11:21
New Member
Join Date: Jan 2006
Location: thorpe le soken
Age: 22
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Externalising Javascript

no worrys any other things i can help you with
Reply With Quote
  #5 (permalink)  
Old Jan 14th, 2006, 16:20
Junior Member
Join Date: Dec 2005
Location: Leeds
Age: 35
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
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


Reply With Quote
  #6 (permalink)  
Old Jan 14th, 2006, 18:01
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
Re: Externalising Javascript

yes, u do delete those lines, and you can put as much javascript as u like in one file
Reply With Quote
  #7 (permalink)  
Old Jan 15th, 2006, 01:25
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
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)
Reply With Quote
Reply

Tags
externalising, javascript

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 10:35.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43