
Als ich mein Blog (endlich) auf XHTML umstellen wollte, hatte ich ja wie bereits erwähnt, erst mit der Transitional-Variante angefangen. Das hatte eigentlich nur einen einzigen Grund: Bei XHTML Strict ist in Links kein target
-Attribut erlaubt. Ich will mich auch überhaupt nicht auf irgendwelche Diskussionen darüber einlassen, ob man als Webmaster den User bevormunden darf, indem man das Öffnen neuer Fenster erzwingt oder nicht. Dazu gibt es im Web Hunderte, Tausende und Millionen von Meinungen, Threads und Posts, die mich allesamt nicht interessieren. Am Ende bleibt es ja doch eine Frage des Geschmacks – so wie Apple oder PC, Windows oder Unix, Porsche oder Ferrari, Kaffee oder Tee, Picard oder Kirk.

When I wanted to convert my blog to XHTML (finally), I first started with the Transitional version. There was really only one reason for that: in XHTML Strict, the target
attribute is not allowed. I don’t want to get involved in any discussions about whether or not a webmaster may infantilize the user by forcing new windows to open. There are hundreds, thousands and millions of opinions, threads and posts on the web about that, all of which I don’t care about. In the end, it remains a matter of taste – just like Apple or PC, Windows or Unix, Porsche or Ferrari, coffee or tea, Picard or Kirk.
Ich persönlich mag es überhaupt nicht, wenn ich auf einen externen Link klicke und dieser sich nicht in einem neuen Fenster/Tab öffnet, sodaß ich – je nachdem, wie lange ich noch auf der neuen Seite herumklicke – zigmal den „Zurück“-Button betätigen muß, um wieder zur Ursprungsseite zurück zu gelangen.
Dennoch entschied ich mich schließlich doch für XHTML Strict. Um trotzdem die target
-Funktionalität beibehalten zu können, habe ich ein JavaScript geschrieben, das ich aus zwei anderen, die ich im Netz fand:“Strict HTML/XHTML and target=”_blank”(Qian Qin)“:http://www.qianqin.de/de/2008/06/11/strict-htmlxhtml-and-target_blank/ :“Open External Links in New Window Automatically(CSS Globe)“:http://cssglobe.com/post/1281/open-external-links-in-new-window-automatically , die mir aber beide nicht hundertprozentig zusagten, zusammengebastelt habe.
Dies ist das Ergebnis:
function externalLinks() {
if(!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for(var i=0; i
Dieses Script kann man nun einfach in einer Textdatei speichern und diese z. B. externalLinks.js
nennen. Dann bindet man sie nach folgendem Muster in den head
-Bereich seiner Seite ein:
Von jetzt an verwendet man in seinen Links nicht mehr target="_blank"
, sondern rel="external"
. Alle auf diese Weise ausgezeichneten Links werden nun automatisch von unserem JavaScript in einem neuen Fenster geöffnet. (Für Benutzer mit deaktiviertem JavaScript verhalten sie sich einfach wie ganz normale Links und öffnen sich im selben Fenster.)
[:]
[:en]
Personally, I don't like it at all when I click on an external link and it doesn't open in a new window/tab, so that - depending on how long I click around on the new site - I have to hit the "Back" button umpteen times in order to get back to the original site.
Nevertheless, I decided for XHTML Strict after all. In order to still keep the target
functionality I wrote a JavaScript which I pieced together from two others that I found on the net:"Strict HTML/XHTML and target=”_blank”(Qian Qin)":http://www.qianqin.de/2008/06/11/strict-htmlxhtml-and-target_blank/ :"Open External Links in New Window Automatically(CSS Globe)":http://cssglobe.com/post/1281/open-external-links-in-new-window-automatically , but that didn't suit me a hundred percent.
This is the result:
function externalLinks() {
if(!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for(var i=0; i
You can simply save this script in a text file and for example call it externalLinks.js
. Then you implement it in the head
area of your page according to this sample:
From now on, you don't use target="_blank"
in your links anymore, but rel="external"
. All links marked like that will now automatically be opened in a new window by our JavaScript. (For users with JavaScript disabled, they will simply behave like ordinary links and open in the same window.)
[:]
10 Antworten zu “[:de]Links XHTML-konform in neuem Fenster öffnen[:en]Open links in new window XHTML-conform[:]”
PC, Windows, Porsche, Tea, Picard.
And you?
Sean Connery or Roger More? Sleeping on side or back? Using one pillow or two? Using a desktop or laptop?
PC, Windows, Porsche (although I don’t care very much about cars in general).
There is absolutely no way to make me decide between coffee and tea, and the same goes for Picard and Kirk!
The rest is quite easy: Sean Connery, on back, two pillows, desktop.
(Reads quite funny if you take it out of its context.)
I guess I would like a laptop though, if I owned one…
Roger Moore, Side, two pillows, desktop!
How can you not chose between Picard and Kirk? I mean come on! Kirk was awesome, he defined what a captian should be. But Picard was just … perfect.
I love him, a little.
There is one aspect about Kirk that you don’t take heed of as a man.

Try to read it from these ladies‘ faces:
neues Fenster und alte Rechtschreibung, Windoof/Linux/Unix, Audi 80, Milchkaffee und Sisco.
Aber wie dem auch sei mit den Geschmäckern – tausend Dank für das Script, denn lieber zig Fenster als x-mal zurück-zurück-zurück…
Grüßles – Rosie
Sisco! Du Verräter! :D
Boah – Verräter!
das ja mal ein hartes Stück Brot *knabber* ;)
das geht auch knapper. sowohl im JS als auch im markup
Jaaa… Also, ob ich nun „ex“ oder „external“ schreibe – ich bevorzuge eigentlich immer extrem sprechende Bezeichner, von daher wählte ich „external“. Soviel Zeit muß sein. :)
Und Dein JS ist gut und schön – wenn man ein Framework wie Prototype benutzt. Vielleicht benutzt man ja aber ein anderes – oder gar keins? ;) Sowas soll es tatsächlich noch geben (bei mir beispielsweise). :)
Trotzdem danke für Deinen Hinweis, ist natürlich eine nette Abkürzung.