JavaScript
  Home arrow JavaScript arrow Page 2 - Handling Remote Files with JavaScript Clic...
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

Handling Remote Files with JavaScript Click Interceptions
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-11-26

    Table of Contents:
  • Handling Remote Files with JavaScript Click Interceptions
  • Showing the contents of several text files in different windows
  • Loading the contents of several text files without web page reloads
  • The full source code of the text file reading application

  • 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


    Handling Remote Files with JavaScript Click Interceptions - Showing the contents of several text files in different windows


    (Page 2 of 4 )

    As I explained at the beginning, first I’m going to build a rudimentary web page that contains a bunch of links. Once the links have been created, they will open distinct sample text files in a new window, a functionality you've probably coded dozens of times before.

    So, I’ll start by building four basic text files, whose respective signatures are listed below:

    (definition of textfile1.txt file)


    This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1. This is the content of text file 1.


    (definition of textfile2.txt file)


    This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2. This is the content of text file 2.


    (definition of textfile3.txt file)


    This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3. This is the content of text file 3.


    (definition of textfile4.txt file)


    This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4. This is the content of text file 4.


    As you can see, the respective definitions of the above sample text files are actually fairly trivial, yet they’ll be more than enough to demonstrate another case where click interceptions can be really useful. But I’m getting ahead of myself; having created the files in question, the only thing that remains undone is building a group of links that load the contents of these files in a different window.

    With that concept in mind, you will see below a brand new web page that includes precisely those links:


    <!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>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Example on reading text files</title>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #fff;

    }

    h1{

    font: bold 18pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    h2{

    font: bold 16pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    a:link,a:visited{

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #00f;

    }

    a:hover{

    color: #f90;

    }

    p{

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    #linkcontainer{

    width: 300px;

    padding: 5px;

    background: #ffc;

    }

    #filecontainer{

    width: 300px;

    }

    </style>

    </head>

    <body>

    <h1>Example on reading text files</h1>

    <div id="linkcontainer">

    <ul>

    <li><a href="textfile1.txt" title="Read contents of text file here...">Read contents of text file 1...</a></li>

    <li><a href="textfile2.txt" title="Read contents of text file here...">Read contents of text file 2...</a></li>

    <li><a href="textfile3.txt" title="Read contents of text file here...">Read contents of text file 3...</a></li>

    <li><a href="textfile4.txt" title="Read contents of text file here...">Read contents of text file 4...</a></li>

    </ul>

    </div>

    <div id="filecontainer"></div>

    </body>

    </html>


    Well, certainly you’ll have to agree with me that the above web document is very simple! As you can see, it contains a list of regular links. When clicked on, these links will load the contents of different text files in the same window. That’s precisely the default behavior of these links, something that’s clearly illustrated by the following screen shot:



    So far, everything looks good, right? If you test the previous web page, along with the four text files created earlier, you’ll see that each time you click on one link, the contents of a specific file will be neatly fetched by the browser, and the whole web page will be reloaded. However, and here’s where click interceptions come in, I’d like to change this behavior and make these contents be displayed within a unique DIV on the same web document, without any additional web page reloads.

    Is it possible to do such a thing? Of course it is. By means of a few click interceptions I’ll show you how to load the contents of these sample text files on the same web page.

    This topic will be covered in detail in the following section, so jump ahead and read the next few lines. I’ll be there, waiting for you.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this last chapter of the series, click interceptions are used to modify the...
     

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek