|
| |
|
|
|
|
spinningjennie
Posts: 326 Joined: 2/20/2002 From: Status: offline
|
Alternatives to target=_blank for xhtml strict - 7/3/2006 6:29:29
What is the best alternative for target=_blank when using xhtml 1.0 strict? The w3c validator rejects it. I want my external links to open in a new window, so that if a viewer closes the window, they get back to my website. I've tried the following: 1. Used javascript in this page to link to this external.js file which contains the following code but I can't get it to work: function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; } } 2. I've also added text beside the links in this alternative page to get the viewer to use Shift + Click to open the links. It does work but I think it looks a bit unusual. 3. As an alternative I might change my document type from Strict HTML to Transitional HTML so that target=_blank is accepted. I haven't tried this yet. I would have to compromise on strict xhtml, so I was reluctant. Any advice much appreciated! spinningjennie
|
|
|
|
spinningjennie
Posts: 326 Joined: 2/20/2002 From: Status: offline
|
RE: Alternatives to target=_blank for xhtml strict - 7/3/2006 22:10:45
Thanks so much Reflect and Tailslide! 1. Tailslide's suggestion works very neatly with little code. 2. Reflect, the link you provided gave the SitePoint link where I got the javascript code in my 1st post. I've now got that external.js file to work. I just needed to add the last line of code: window.onload = externalLinks; A big thanks! spinningjennie
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|