Saturday, May 4

Cut and paste code

Cut and paste code

Article title: Cut and paste code into HTML

Author: Gastd

Introduction

When working on a web site sooner or later the time will come when you will be asked to cut/copy some code and paste it into your website. Good examples are various Javascripts, HTML code for banners and similar.

The problem

Below is some sample Javascript code. Copy and paste it into your web page and make sure it displays where YOU want.
You need to paste this code into the HTML source code to make it work. When done your browser should only display Testing 123 where the code is located and no extra code!
Cutting and pasting code into your web page is easy if you have some HTML knowledge. If not you have probably tried to paste it from your WYSIWYG editor (like FrontPage, DreamWeaver, CoffeCup etc.). These and similar editors usually mess up the code, especially Javascript. The result is either non-working feature or the result does display but not where you want it to display.

Solution - how to cut and paste

There is a very simple and fool-proof trick of doing it. Just follow these steps:
Step 1: Open the page where you want to paste the javascript code to in your favorite HTML editor.
Step 2: Where you want the result of the code to appear simply type CODE_HERE (see example below).
Step 3 Save changes then open the HTML file in a plain text editor, like Notepad or Wordpad in Windows (do not use Word). You will see a bunch of code there, don't let it scare or confuse you. Use editor's search function to find CODE_HERE within the HTML code.
Step 4 Simply delete CODE_HERE and replace it with the code you want to paste, like the Javascript sample above.
Step 5 Save the file and open it in your browser. If you used the sample code from above then Testing 123 will appear in the exact spot where you typed CODE_HERE originally.
Wasn't that hard, was it? That's all there is to it. You can use these five easy steps to paste any kind of code into your web page exactly where you want it.

Copyright notice

This tutorial is copyrighted by Gastd. Obtain permission before copying, re-publishing or otherwise redistributing this article.

No comments: