|
You are here: PHPJunkyard > Free tutorials > Cut and paste code into HTML
Article title: Cut and paste code like Javascript into HTML
Author: Klemen Stirn
Intro
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.
<script language="Javascript"><!--
document.write("<b>Testing 123</b>");
//-->
</script>
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 NOTHING ELSE!
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
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

Screenshot 1: Write CODE_HERE in your HTML editor
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.

Screenshot 2: Find CODE_HERE in the source code
Step 4: Simply delete CODE_HERE and replace it with the code you want
to paste, like the Javascript sample above.

Screenshot 3: Replace CODE_HERE with your copied code
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 place where you typed
CODE_HERE

Screenshot 4: Save file and view result in browser
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 Klemen Stirn. Obtain permission before copying,
re-publishing or otherwise redistributing this article.
|