Replacing JavaScript
If you need to replace the JavaScript on a website, there are a number of places you may need to look. Websites use JavaScript that is stored in many different places. Some JavaScript code may be on the website pages themselves, stored in the page head section or within the body HTML, which is known as "in-line." Some JavaScript may be stored in separate scripts that are stored either on the same server as the rest of the site or in some other web location.
Instructions
-
-
1
Check web pages for references to JavaScript files. Check the head section in the HTML source of your site pages to find any links to external JavaScript files. The code you must replace may be located in those files. The references to the external files should include an indication of the location of the scripts. Scripts located on the same server as a website page may use a relative URL, in which case the address is relative to the page containing the reference. Scripts referenced in the head of a page may also reside on a different server, in which case the URL will normally be absolute.
-
2
Check the head section of your web pages for included scripts. As well as listing links to external JavaScript, actual code may be contained within the head section of a page. If you're changing the code for a web page, you may therefore be able to do so within the same HTML file. If the web page has been delivered using a server side programming language, it may be saved as ".php" or ".asp," depending on which technology is being used.
-
-
3
Check the main HTML within web pages for "in-line" JavaScript. Often, JavaScript is used within the body of an HTML page, in which case you will be able to see the JavaScript code within the HTML structures and elements. This will normally be included in a "<script>" tag, with the code itself listed between tags. Be careful when making changes to such code, as mistakes may make the page not viewable.
-
4
Check the directories on your web server for additional scripts. Sometimes it may be difficult to identify all of the client-side scripting that is actually functioning on a web page. If you need to find all of it, check the directories on your web server, including the one containing the relevant web pages and any others that have been created. Use caution to ensure you do not delete scripts that you may later require. Download scripts and make copies before you remove them from the server, and make sure you also remove any references to them in your site pages.
-
5
Check the code within external scripts to find functions. Depending on what you are trying to achieve by replacing the JavaScript on a site, you may need to analyze the content of external files. Normally, JavaScript files are organized into sections such as functions. You may see whether these excerpts of code are being used by checking for the functions being called. Some JavaScript runs as soon as the code is included or referenced within a page while some only executes when a function is called.
-
1
Tips & Warnings
Use developer browser tools to help you make the changes you need to JavaScript. These tools can help you to both locate and understand the scripts that a website is using.
Don't change JavaScript until you're sure you understand the consequences. Instead of deleting code, try commenting it out and checking that the site still functions before continuing.