How to Run a Script on a Web Page

A young woman works on a laptop in her home office
Image Credit: 4774344sean/iStock/Getty Images

Web programmers either integrate scripts directly in website code or generate webpages with scripting languages behind the scenes. Scripting languages differ from programming languages because they are interpreted on the fly and don't need to be compiled. Compiled languages like C++ and Java are interpreted before being accessed. Scripting languages are intended to augment other programming languages. JavaScript, PHP, Perl, Ruby, Python and ASP are all commonly implemented scripting languages.

Run A Script

Web pages have three levels or layers that pertain to content, layout and behavior functionality; HTML, CSS and JavaScript respectively pertain to those layers. While there are many scripting languages for the Web, the term refers to JavaScript unless otherwise specified. Adding a script to a site can be as straight-forward as embedding it between the script tags "" in the page's HTML code. Scripts can be placed in the header section or inline with the page content. For example, entering the code "" in the page's code will pop an alert window that says "hello world" when the page loads. However, unsolicited alerts like "hello world" are considered annoying design when used on real pages.

Wait For Action

An actionable script activates when visitors perform actions on a webpage: the action could be loading the page itself. Scripts are used on webpages to do things like activate drop down-menus and interpret user data input. A script can interpret a number value entered into a HTML input field to check how many numbers it is to confirm if it's a phone number or convert temperatures from Celsius to Fahrenheit.

Build A Site

Scripting languages like PHP generate HTML-based Web pages from database information instead of relying on uniquely written pages. Site constructing languages require a sever-based program interpretation like Apache and will not run by opening a file. Web developers employ content management systems that run on top of the server-based interpretation program for large scale websites that automate most of the construction scripting process and provide content creators with an easy-to-use interface. Scripting languages help developers manage page content on a large scale by automatically generating pages. For example, a blog or news article page may only exist as the unique content in the text area; the page header and footer content is pulled in through "includes" statements in PHP.

Construct A Web App

Scripting languages work in tandem with more capable programming languages to render the user interface portion of Web application content through a Web browser. Developers employ Web apps to handle jobs that browser-oriented mark-up and scripting languages can't while still operating inside a Web browser. Web apps don't need to be installed on a computer or device and work through browser-based distribution. Common Web apps include browser games and timekeeping software. While generally read on the fly, scripting languages can be compiled for faster performance, which is useful for Web apps.

references & resources