Creating a Sitemap


this.opener.name = "mainWindow"; 

A sitemap is very convenient on any website. With a bit of JavaScript, this feature can get even better.

If you open a sitemap in a new window, you of course want all the links in a sitemap to open up in the original window. Obviously, this can be done by setting the target attribute of all HTML links (or use <base target="..." />). However, one question remains: Which is the window name? One way to answer this question is to use JavaScript in the main window and set the window's name property:

this.name = "mainWindow"; 


Another way is to use the sitemap and reference the opening window from there. This is done by the opener property of the window, which is set to the parent window of the current window (if there is any parent). The following code is the complete sitemap:

The Sitemap (sitemapwindow.html; excerpt)

[View full width]

<script language="JavaScript"   type="text/javascript"> this.opener.name = "mainWindow"; </script> <a href="http://www.samspublishing.com/"   target="mainWindow">Publisher</a><br /> <a href="http://www.amazon.com/gp/product/0672328801" target="mainWindow">This book at  Amazon</a> 

And this listing opens the sitemap:

Opening the Sitemap (sitemap.html; excerpt)

<script language="JavaScript"   type="text/javascript"> window.open(   "sitemapwindow.html",   "sitemap",   "width=320,height=100,directories=no,menubar=no, toolbar=no,scrollbars=yes"); </script> 




JavaScript Phrasebook(c) Essential Code and Commands
JavaScript Phrasebook
ISBN: 0672328801
EAN: 2147483647
Year: 2006
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net