{"id":164,"date":"2013-06-19T14:25:40","date_gmt":"2013-06-19T12:25:40","guid":{"rendered":"http:\/\/www.zellot.at\/blogs\/?p=164"},"modified":"2013-06-19T14:25:40","modified_gmt":"2013-06-19T12:25:40","slug":"ankeranderungen","status":"publish","type":"post","link":"https:\/\/www.zellot.at\/blogs\/2013\/06\/19\/ankeranderungen\/","title":{"rendered":"Anker\u00e4nderungen"},"content":{"rendered":"<p>Des \u00f6fteren kommt es vor das man anhand des Ankers auch in JavaScript bestimmte Aktionen setzen will, vor allem um z.B. Permalinks zu bieten oder Suchergebnisse, anhand des Links weiter geben zu k\u00f6nnen. <\/p>\n<p>Nach kurzer Suche bin ich \u00fcber folgenden Eintrag in Stackoverflow gesto\u00dfen <a href=\"http:\/\/stackoverflow.com\/questions\/2161906\/handle-url-anchor-change-event-in-js\">http:\/\/stackoverflow.com\/questions\/2161906\/handle-url-anchor-change-event-in-js<\/a>\n<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\nif (&quot;onhashchange&quot; in window) { \/\/ event supported?\n&nbsp;&nbsp;&nbsp;&nbsp;window.onhashchange = function () {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hashChanged(window.location.hash);\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}\nelse { \/\/ event not supported:\n&nbsp;&nbsp;&nbsp;&nbsp;var storedHash = window.location.hash;\n&nbsp;&nbsp;&nbsp;&nbsp;window.setInterval(function () {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (window.location.hash != storedHash) {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;storedHash = window.location.hash;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hashChanged(storedHash);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}, 100);\n}\n<\/code><\/pre><br \/>\nDa in den neueren Browsern das event bereits unterst\u00fctzt wird, kann hier auf die \u00fcbliche Art eine Callbackfunction gelegt werden, f\u00fcr \u00e4ltere Browser geht der Umweg \u00fcber eine Variable als Sicherung und der Pr\u00fcfung auf Zeit ob sich der Hash ge\u00e4ndert hat.<\/p>\n<p>Zus\u00e4tzlich zu den \u00c4nderungen will man auch oft den Hashwert nach Seitenaufbau (z.B. $(document).ready(function(){&#8230;}); ) wissen, hierzu kann einfach nach Seitenaufbau wieder das window Objekt hergenommen werden <\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n if(window.location.hash != null &amp;&amp; window.location.hash != undefined &amp;&amp; window.location.hash != &quot;&quot;){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hashChanged(window.location.hash);\n }\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Des \u00f6fteren kommt es vor das man anhand des Ankers auch in JavaScript bestimmte Aktionen setzen will, vor allem um z.B. Permalinks zu bieten oder Suchergebnisse, anhand des Links weiter geben zu k\u00f6nnen. Nach kurzer Suche bin ich \u00fcber folgenden Eintrag in Stackoverflow gesto\u00dfen http:\/\/stackoverflow.com\/questions\/2161906\/handle-url-anchor-change-event-in-js if (&quot;onhashchange&quot; in window) { \/\/ event supported? &nbsp;&nbsp;&nbsp;&nbsp;window.onhashchange = [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[44,45,46],"class_list":["post-164","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-hash","tag-window","tag-window-location"],"_links":{"self":[{"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":1,"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/posts\/164\/revisions\/165"}],"wp:attachment":[{"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zellot.at\/blogs\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}