Re: howto : link opens a new window?
"Jason Judge" <[email protected]> Thu, 4 Sep 2003 00:47:48 +0100
| Newsgroups | gmane.comp.cms.xaraya.knowledge-base |
|---|---|
| Organization | Xaraya News Server |
| Message-ID | <[email protected]> |
"Tomas Nekvasil" <[email protected]> wrote in message news:[email protected] > http://www.sitepoint.com/article/1041 Very good. In essence, the article describes this: JavaScript to be loaded with every page: function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; } } window.onload = externalLinks; Links to open in a new window: <a href="document.html" rel="external">external link</a> I would probably extend that a little to allow for named windows (using 'external' as a prefix to the target name, for example). I like this solution. Can anyone else see a need for a JavaScript library yet? To be able to put a tag in a template, to indicate that new-window links are used in that template, and then have the appropriate JS file automatically included would be great. That's what I dream of, at least. -- JJ