1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Copy and Paste

clr gif
Join the Discussion

Questions? Comments?

To be able to incorporate pre-built Javascripts into your web page you need to know how to copy and paste code (which is not necessarily quitre the same thing as copying and pasting text).

You will definitely need to copy Javascript and HTML code in order to add a pre-built Javascript to your web page. You may need to copy stylesheet (CSS) code as well.


How you copy the necessary code depends on how it is presented to you. There are basically three ways that the code can be presented to you to copy. The first way is that the code is displayed directly on the web page - usually highlighted in some way so that you can tell what you have to copy. Here's an example:

function sample() {

To copy the code when it is displayed in the page like this you click at the start of the code with your left mouse button and then with the mouse button held down you move the mouse to the end of the code you want to copy. The selection should be highlighted to let you know what is selected. You can next click the right mouse button on the selected code and select copy from the context menu. (Note that we are copying text, we will need to paste it as code though).

An alternate way that the code may be presented to you is in a form like this:

In most cases the actual code presented extends well beyond the few lines that are displayed in the form field. You can select and copy this text the same way as you did for that displayed on the page directly but you need to remember to continue to drag downwards until all of the code has been selected and not just that part visible in the field at the start.

Sometimes the code will be made easier to select through the author having provided a button that you can use to select all of the code in one go - like the "Highlight All" button in the above example. If a button like this is provided then you just click on the button to select all of the text and then right click on the selection and select copy.

The third way that the code may be provided to you (particularly for complex scripts) is via a zip file. To obtain the code in this instance you click on the link provided and save the zip file to your computer. You then need to use compression software such as WinZip (Windows only) or Aladdin Stuffit (available for Mac, Windows, Linux, Solaris) to decompress the file and extract the contents into separate files.


There are three places where you may have to paste your code. The instructions that come with the script should tell you what to paste where.

One place where you may need to paste code (Javascript and/or CSS) is into new files. To do this you open notepad (or whatever plain text editor that is available for your operating system) and select paste from the edit menu. You then save the new file as whatever name that the instructions tell you to use making sure that Javascript files end with .js and stylesheet files end in .css so that you know which is which.

The other two places where you may need to paste code (Javascript, CSS or HTML) is into either the head or body section of your web page. Exactly how you do this depends on which web editor program you use because that is what you will need to use to paste the code.

If the web editor allows you to work directly with the HTML code itself then switch to that mode and use the paste option supplied by that software to paste your copied Javascript, stylesheet, or HTML code into either the head section of the page (if that is where the instructions said to put it) or into the exact spot in the body of the page where you want the output from the script to appear (for scripts that go into the body of the page).

If your web editor doesn't allow you to edit the code directly then you need to check if it offers an option that allows you to attach code to your page. If so then use that to attach the code to the required places in the page.

If your web editor doesn't handle code at all then you will need to use an alternative editor (eg. notepad) that does support editong the web page code in order to apply your changes. Hopefully in this case the web editor that you usially use will recognise and retain changes that are made outside of that editor or you will lose your changes when you reopen the page in your usual editor. If this happens then the only option that you have is to change to a different web editor.

The one thing that doesn't work is to use a paste as text option that some web editors offer since using that will just result in the code being displayed in the web page itself rather than being run by the page to perform the required function.

©2017 About.com. All rights reserved.