Free PHP scripts

Hosting with unlimited domains, 100GB space, 1000GB transfer

Cut and paste code into HTML

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

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

Find CODE_HERE in the source 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.

Replace CODE_HERE with your copied code
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

Save file and view result in browser
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.

 


 

Thanks for support to
Junkyard
Email Hosting
Free Link Exchange
Short URL
PHP forms
Buy PHPJunkyard author a beer (DONATE)
Other links
Direct TV Satellite
Managed Hosting
DWI lawyer Dallas
California criminal defense attorney
Anxiety
Dish Network
Investing
Buy candle holders

Free PHP scripts | Text hit counter | Graphical counter | Click counter | Link manager | Guestbook | Message board
Help desk software | Resources | PHP hosting | PHP books | Free tutorials | FTP/Chmod tutorial | Link to us
Help PHPJunkyard | Remove copyright | Advertise | Support Forum | Contact author | Invite a friend | Links

© Copyright 2004-2008 PHPJunkYardTM. All rights reserved. |
No part of this website may be reproduced, copied and/or distributed in any medium without express written permission
This website is not allowed to be listed in any auto-surf, pay-to-surf, pay-to-read, or pay-to-click services
Trademarks are property of their respective owners