Posts etiquetados ‘Javascript’

To link to external JavaScript, use Script tags. These attributes will attach another JavaScript to the page, allowing further JavaScript code to then be run. A simple function can perform this processing by utilizing the DOM.

function addJavascript(jsname,pos) {
var th = document.getElementsByTagName(pos)[0];
var s = document.createElement(‘script’);

This function adds the necessary script tag into the end of the head or body section of the page. Call that function the name of the file that contains the extra code to be included and specify to add the function to the end of the head or the end of the body.


Once the script tags have been added to the page, any functions can be called from within that file.

There is no need to write the same script over again to run the same JavaScript on several pages in a web site.  Instead, create an external JavaScript file with a .js extension, and refer to it using the src attribute in the <script> tag.

One thing that Javascript is often used for is to update the content of a web page. This is best done using the Document Object Model (DOM) but is sometimes done using innerHTML.

 Fuente: Link