{"id":859,"date":"2008-12-20T19:31:13","date_gmt":"2008-12-20T18:31:13","guid":{"rendered":"http:\/\/blog.ginchen.de\/?p=859"},"modified":"2010-01-17T08:38:28","modified_gmt":"2010-01-17T06:38:28","slug":"links-xhtml-konform-in-neuem-fenster-oeffnen","status":"publish","type":"post","link":"http:\/\/blog.ginchen.de\/en\/2008\/12\/20\/links-xhtml-konform-in-neuem-fenster-oeffnen\/","title":{"rendered":"Open links in new window XHTML-conform"},"content":{"rendered":"<a href=\"http:\/\/blog.ginchen.de\/wp-content\/uploads\/2008\/12\/kirk_picard.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.ginchen.de\/wp-content\/uploads\/2008\/12\/kirk_picard-200x142.jpg\" alt=\"Picard or Kirk?\" title=\"Picard or Kirk?\" width=\"200\" height=\"142\" class=\"alignleft size-thumbnail wp-image-1018\" srcset=\"http:\/\/blog.ginchen.de\/wp-content\/uploads\/2008\/12\/kirk_picard-200x142.jpg 200w, http:\/\/blog.ginchen.de\/wp-content\/uploads\/2008\/12\/kirk_picard-300x213.jpg 300w, http:\/\/blog.ginchen.de\/wp-content\/uploads\/2008\/12\/kirk_picard.jpg 500w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a>\r\n\r\n<p>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&nbsp;Strict, the <code>target<\/code> attribute is not allowed. I don&#8217;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&#8217;t care about. In the end, it remains a matter of taste &#8211; just like Apple or PC, Windows or Unix, Porsche or Ferrari, coffee or tea, Picard or Kirk.<\/p>\r\n\r\n\r\n<!--more-->\r\n\r\n\r\n\r\n\r\n<p>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.<br \/>\r\nNevertheless, I decided for XHTML&nbsp;Strict after all. In order to still keep the <code>target<\/code> functionality I wrote a JavaScript which I pieced together from two others that I found on the net:\"Strict HTML\/XHTML and target=\u201d_blank\u201d(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.<\/p>\r\n\r\n<p>This is the result:<\/p>\r\n\r\n<pre lang=\"javascript\">\r\nfunction externalLinks() {\r\n\tif(!document.getElementsByTagName) return;\r\n\tvar anchors = document.getElementsByTagName(\"a\");\r\n\tfor(var i=0; i<anchors.length; i++) {\r\n\t\tvar anchor = anchors[i];\r\n\t\tif(anchor.getAttribute(\"href\") &#038;&#038; anchor.getAttribute(\"rel\") == \"external\") anchor.target = \"_blank\";\r\n\t}\r\n}\r\n\r\nthis.addEvent = function(obj, type, fn) {\r\n\tif(obj.attachEvent) {\r\n\t\tobj['e'+type+fn] = fn;\r\n\t\tobj[type+fn] = function() { obj['e'+type+fn](window.event ); }\r\n\t\tobj.attachEvent('on'+type, obj[type+fn]);\r\n\t} else {\r\n\t\tobj.addEventListener(type, fn, false);\r\n\t};\r\n};\r\naddEvent(window, \"load\", externalLinks);\r\n<\/pre>\r\n\r\n<p>You can simply save this script in a text file and for example call it <code>externalLinks.js<\/code>. Then you implement it in the <code>head<\/code> area of your page according to this sample:<\/p>\r\n\r\n<pre lang=\"html4strict\">\r\n<script type=\"text\/javascript\" src=\"http:\/\/www.domain.com\/js\/externalLinks.js\"><\/script>\r\n<\/pre>\r\n\r\n<p>From now on, you don't use <code>target=\"_blank\"<\/code> in your links anymore, but <code>rel=\"external\"<\/code>. 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.)<\/p>","protected":false},"excerpt":{"rendered":"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&nbsp;Strict, the target attribute is not allowed. I don&#8217;t want to get involved in any discussions about whether or not a webmaster may infantilize the user by forcing new [&hellip;]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[139,76],"tags":[176,178,154,600,179,177,152],"_links":{"self":[{"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/posts\/859"}],"collection":[{"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/comments?post=859"}],"version-history":[{"count":23,"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/posts\/859\/revisions"}],"predecessor-version":[{"id":3000,"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/posts\/859\/revisions\/3000"}],"wp:attachment":[{"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/media?parent=859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/categories?post=859"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ginchen.de\/en\/wp-json\/wp\/v2\/tags?post=859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}