Script Outside Page Source

Posted by Planeta Srbija | 21.10.08 | , | 1 comments »

If you'd rather like to have your page source as clean as possible then you want to keep your scripts separately.

1. Make a folder and name it like "scripts" (or whatever).
2. Take the scriptcode and paste it in notepad! For example it looks like:

<script type="text/javascript">
function nextQuote(){
var result = new Array(6);
result=jsonrpc.slideQuotes.getNextQuote();
document.getElementById('quoteBody').innerHTML=result[0];
document.getElementById('quoteHeading').innerHTML=result[1];
document.getElementById('quotePrevious').innerHTML=result[4];
document.getElementById('quoteNext').innerHTML=result[5];}
</script>


Delete the red part and save the document as "quoteSlideshow.js"

3. Put this document into your "scripts" folder.
4. In your source code (on your page) there where you want to use this script put following string:

<script type="text/javascript" src="/scripts/quoteSlideshow.js"></script>

1 comments

  1. Vcom Infotech Company // 15 May 2017 at 12:17  

    Informative for the clean coding concept. Thank you very much. kovai e solutions | e-commerce online coimbatore

Take a look on my other postings: