Get the App
SLTechnology News&Howtos  ›  Development  › 

What interprets and executes javascript scripts

Shulou Source: shulou.com Published: 2022-06-02 01:26:58 09月22日 Update

This article will introduce in detail "javascript script is by what interpretation and execution", the content steps are clear and detailed, the details are properly handled, and Xiaobian will update different knowledge points every day, I hope this article "javascript script is by what interpretation and execution" can give you unexpected gains, please follow Xiaobian's thinking slowly, the specific content is as follows, together to harvest new knowledge bar.

JavaScript scripts are interpreted and executed by browsers, and javascript scripts are executed: 1. Browsers execute scripts when opening pages;2. Use onLoad events to execute scripts;3. Use user events to execute scripts.

Operating environment: Windows 7 system, javascript version 1.8.5, DELL G3 computer

Javascript scripts are interpreted and executed by browsers.

When will javascript scripts be executed?

Javascript scripts can be embedded anywhere in html, but when is it invoked? When the browser opens the HTML file, it will directly run a script that is not a declaration function or call a script function through an event. The following analysis of these cases.

1. Browser executes script when opening page

When a browser opens an HTML file, it interprets the entire file from scratch, including html tags and scripts. If there are statements in the script that can be executed directly, they will be interpreted and executed as soon as they are encountered. There are two main situations:

1). This alert triggers the execution of functions like this.

demo alert("dare you click me once again");

2). The js function is automatically invoked as the browser loads (not triggered by user clicks, etc.)

2. Executing scripts with onLoad events (equivalent to listening for ** to occur and then executing)

The onLoad event occurs when a page is opened in a browser. This method is often used to display messages to the user while a page is open.

The following example demonstrates the onLoad event of the tag:

demo //insert javascript code here. function display() { alert("dare you click me once again") }

3. Executing scripts with user events

Users often use the mouse and keyboard to perform some operations when using the browser. Moving the mouse proportionally, clicking links or buttons, these operations will generate corresponding events. We can use these events to invoke script functions.

The following example uses a button click event to invoke the display() function.

demo //insert javascript code here. function display(){ alert("you click me ,it is so pain") }

Tags: Scripts browsers browsing events users interpretations functions pages are made up of content situations files examples buttons tags mice processing practice different proper Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Shulou Tech Info macOS Microsoft