How To Insert A Script Into A Page

Table of contents:

How To Insert A Script Into A Page
How To Insert A Script Into A Page

Video: How To Insert A Script Into A Page

Video: How To Insert A Script Into A Page
Video: Adding a Script 2024, May
Anonim

Most likely, the script you need to insert into the page is written in either PHP or JavaScript - these are the two most common scripting languages today. They are not inserted in the same way, let's look at both options.

How to insert a script into a page
How to insert a script into a page

Instructions

Step 1

JavaScript scripts are scripts that are not executed on the server, but directly in the browser, which is why they are called "client-side". If the script came to you as a separate file with the "js" extension, then you need to connect it to the page by adding a corresponding tag with a link to this file to the heading part of its HTML code. The header is the part that starts with a tag and ends with a tag. Therefore, you can't go wrong if you find a closing tag in the page code and place the following link to an external JavaScript file in front of it: Here, the src attribute specifies the file name "script.js" - you need to replace it with the name of your js file. In order for the browser to find and read this file, it must be placed in the same server folder where the page itself is located. If you upload it to another place, specify the corresponding address along with the file name in the src attribute. If you have JavaScript not in a separate file, but simply as text starting with a tag

Step 2

PHP scripts are executed on the server side and are called, respectively, "server". And here, too, if the script came to you as a separate file, then you need to add a link to it in the page code. In PHP, such a link may look like this: Here is the name script.php - you need to replace it with the name of the file you have. You need to insert such code at the very beginning of the page, before all the tags present in it. It is important to make sure that there are no blank lines or spaces in front of the php code. If the page into which the code is inserted has the extension htm or html, then the php-code will not be executed by the server - the extension must be exactly "php". If the PHP-code of the script is not in a separate file and starts with the <? Php or just <?, then you need to insert it directly into the page, without linking to an external file. Such blocks of PHP-code can be scattered over different parts of the HTML-code of the page. With regard to PHP-serips, the presence of the instruction is even more important than for client-side scripts - incorrect use of server-side scripts can spoil your website files stored on the server!

Step 3

The very same procedure for inserting code into the page is the same for both server and client scripts. If you have a file, the first step is to upload it to the server. This can be done according to the FTP-protocol, using a special program (FTP-client). Finding such an application on the web is not difficult - for example, Cute FTP, FlashFXP, FileZilla, WS FTP, Smart FTP, etc. Downloading using FTP clients is performed using the FTP protocol (File Transfer Protocol). But you can upload the file directly through the browser, using the file manager available in the content management system and in the hosting control panel. After uploading the file (or files) to the server, you will need to edit the HTML code of the page. This can also be done through a browser if you are using a content management system. The system must have a page editor in which you need to open the required page, switch the editor to the HTML code editing mode, insert the prepared code and save the changes. If there is no control system, then download the page to your computer, edit it with a simple text editor and upload it back to the server.

Recommended: