JavaScript
  Home arrow JavaScript arrow Page 2 - Dynamic Text Replacement with JavaScript
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Dynamic Text Replacement with JavaScript
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-09-19

    Table of Contents:
  • Dynamic Text Replacement with JavaScript
  • Using Dynamic Text Replacement in a concrete case
  • Seeing Dynamic Text Replacement in action
  • Completing the dynamic text-replacement script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Dynamic Text Replacement with JavaScript - Using Dynamic Text Replacement in a concrete case


    (Page 2 of 4 )

    To demonstrate how Dynamic Text Replacement  can be used, I'm going to create a sample web page with a typical three-column layout. In this case, each section of the page will include a few text-based <h2> headers, which as you’ll see shortly will be replaced by some appealing images.

    But I’m getting ahead of myself, so first let me show you the definition of this sample web page. It’s as follows:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Sample Web Page - contains text-based 'h2'
    headers</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-
    8859-1" />
    <style type="text/css">

    body{
      padding: 0;
      margin: 0;
     
    background: #039;
    }

    h2{
     
    margin: 0;
     
    font: bold 18px Arial, Helvetica, sans-serif;
     
    color: #000;
    }

    p{
     
    font: normal 12px Arial, Helvetica, sans-serif;
     
    color: #000;
    }

    #header{
     
    width: 780px;
     
    padding: 10px;
     
    margin-left: auto;
     
    margin-right: auto;
     
    background: #ffc;
    }

    #navbar{
     
    width: 780px;
     
    padding: 10px;
     
    margin-left: auto;
     
    margin-right: auto;
     
    background: #fc0;
    }

    #navbar ul{
     
    list-style: none;
    }

    #navbar li{
     
    display: inline;
     
    padding-right: 4%;
    }

    #navbar a:link,#navbar a:visited{
     
    font: normal 12px Arial, Helvetica, sans-serif;
     
    color: #039;
     
    text-decoration: none;
    }

    #navbar a:hover{
     
    text-decoration: underline;
    }

    #mainwrapper{
     
    clear: both;
     
    width: 800px;
     
    height: 100%;
     
    margin-left: auto;
     
    margin-right: auto;
     
    overflow: hidden;
     
    background: #eee;
    }

    #mainwrapper .leftcol{
     
    position: relative;
      float: left;
    }

    #mainwrapper .rightcol{
     
    position: relative;
     
    float: right;
    }

    #leftbar{
     
    width: 180px;
     
    padding: 10px;
    }

    #centerbar{
     
    float: left;
     
    width: 380px;
     
    padding: 10px;
     
    background: #fff;
    }

    #rightbar{
     
    width: 180px;
     
    padding: 10px;
    }

    #footer{
     
    clear: both;
     
    width: 780px;
     
    padding: 10px;
     
    margin-left: auto;
     
    margin-right: auto;
     
    background: #ffc;
    }
    </style>
    </head>
    <body>
     
    <div id="header">
       
    <h2>This is the header section of the web page</h2>
       
    <p>Contents for header section go here. Contents for header
    section go here. Contents for header section go here. Contents
    for header section go here.</p>
     
    </div>
     
    <div id="navbar">
       
    <h2>This is the navigation bar of the web page</h2>
       
    <ul>
         
    <li><a href="#">Link 1</a></li>
         
    <li><a href="#">Link 2</a></li>
         
    <li><a href="#">Link 3</a></li>
          
    <li><a href="#">Link 4</a></li>
         
    <li><a href="#">Link 5</a></li>
         
    <li><a href="#">Link 6</a></li>
       
    </ul>
     
    </div>
     
    <div id="mainwrapper">
       
    <div id="leftbar" class="leftcol">
         
    <h2>This is the left column of the web page</h2>
          <p>Contents for left column go here. Contents for left
    column go here. Contents for left column go here. Contents for
    left column go here. Contents for left column go here. Contents
    for left column go here. Contents for left column go
    here. Contents for left column go here. Contents for left column
    go here. Contents for left column go here.</p>
        
    </div>
       
    <div id="centerbar" class="leftcol">
         
    <h2>This is the center column of the web page</h2>
         
    <p>Contents for center column go here. Contents for center
    column go here. Contents for center column go here. Contents for
    center column go here. Contents for center column go here.
    Contents for center column go here. Contents for center column
    go here. Contents for center column go here. Contents for center
    column go here. Contents for center column go here.</p>
         
    <p>Contents for center column go here. Contents for center
    column go here. Contents for center column go here. Contents for
    center column go here. Contents for center column go here.
    Contents for center column go here. Contents for center column
    go here. Contents for center column go here. Contents for center
    column go here. Contents for center column go here.</p>
         
    <p>Contents for center column go here. Contents for center
    column go here. Contents for center column go here. Contents for
    center column go here. Contents for center column go here.
    Contents for center column go here. Contents for center column go here. Contents for center column go here. Contents for center
    column go here. Contents for center column go here.</p>
       
    </div>
       
    <div id="rightbar" class="rightcol">
         
    <h2>This is the right column of the web page</h2>
         
    <p>Contents for right column go here. Contents for right
    column go here. Contents for right column go here. Contents for
    right column go here. Contents for right column go here.</p>
       
    </div>
      
    </div>
     
    <div id="footer">
       
    <h2>This is the footer section of the web page</h2>
       
    <p>Contents for footer section go here. Contents for footer
    section go here. Contents for footer section go here. Contents
    for footer section go here. Contents for footer section go
    here.</p>
     
    </div>
    </body>
    </html>

    As I explained earlier, the previous web document implements a simple three-column layout, and includes a bunch of text-based <h2> headers. If you execute the above source code on your browser, you should end up with a web page that looks similar to this:

    As you can see on the above screen shot, even when the pertinent web page has been spiced up with some raw CSS styles, the corresponding <h2> headers aren’t truly eye-catching elements. Here is where Dynamic Text Replacement comes in. In the section to come I’ll show you how to substitute them with more appealing graphics with the help of JavaScript.

    To see how Dynamic Text Replacement will be used in conjunction with the previous web page, please jump forward and read the next few lines. I’ll be there, waiting for you.

    More JavaScript Articles
    More By Alejandro Gervasio


       · As you may have heard, Dynamic Text Replacement is a powerful approach that allows...
       · Frequently users cut and paste from Word or some other word processing application...
       · Thank you for the comments on my article on using dynamic text replacement, and also...
       · Hi, how do search engines view this technique?It sounds bit like underhand tactics...
       · Thank you for the comments on my article on dynamic text replacement. Concerning...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT