How to Run a Script on a Web Page

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
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.

Advertisement

Run A Script

Video of the Day

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.

Advertisement

Video of the Day

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.

Advertisement

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.

Advertisement

Advertisement

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.

Advertisement

Advertisement

references & resources

Report an Issue

screenshot of the current page

Screenshot loading...