List anchor in a document : Anchor « HTML « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » HTML » Anchor 
List anchor in a document

/*
Examples From
JavaScript: The Definitive Guide, Fourth Edition

Legal matters: these files were created by David Flanagan, and are
Copyright (c) 2001 by David Flanagan.  You may use, study, modify, and
distribute them for any purpose.  Please note that these examples are
provided "as-is" and come with no warranty of any kind.

David Flanagan
*/
/*
 * FILE: listanchors.js
 * The function listanchors() is passed a document as its argument and
 * opens a new window to serve as a "navigation window" for that
 * document. The new window displays a list of all anchors in the document.
 * Clicking on any anchor in the list causes the document to scroll to 
 * the position of that anchor.  A document should not call this
 * function on itself until it is fully parsed, or at least until all
 * the anchors in it are parsed.
 */
function listanchors(d) {
    // Open the new window.
    var newwin = window.open("""navwin"
                             "menubar=yes,scrollbars=yes,resizable=yes," +
                             "width=600,height=300");

    // Give it a title.
    newwin.document.writeln("<h1>Navigation Window:<br>" +
                            document.title + "</h1>");
    // List all anchors.
    for(var i = 0; i < d.anchors.length; i++) {
        // For each anchor object, determine the text to display. 
        // First, try to get the text between <A> and </A> using a 
        // browser-dependent property. If none, use the name instead.
        var a = d.anchors[i];
        var text = null;
        if (a.texttext = a.text;                          // Netscape 4
        else if (a.innerTexttext = a.innerText;           // IE 4+
        if ((text == null|| (text == '')text = a.name;  // Default

        // Now output that text as a link. Note the use of the location
        // property of the original window.
        newwin.document.write('<a href="#' + a.name + '"' +
                              ' onclick="opener.location.hash=\'' + a.name + 
                              '\'; return false;">'); 
        newwin.document.write(text);
        newwin.document.writeln('</a><br>');
    }
    newwin.document.close();   // Never forget to close the document!
}


           
       
Related examples in the same category
1. Anchor 'target' Example
2.  A Document with Anchors
3. Reading the Number of Anchors
4. Properties of the Anchor Object
5. Anchors array
6. Return the number of anchors in a document
www_.j___a_va_2__s__.__co__m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.