{"id":1518,"date":"2021-03-24T14:41:32","date_gmt":"2021-03-24T13:41:32","guid":{"rendered":"https:\/\/ekiwi.de\/?p=1518"},"modified":"2021-03-26T09:51:51","modified_gmt":"2021-03-26T08:51:51","slug":"html-navigation-mit-dropdown-und-javascript","status":"publish","type":"post","link":"https:\/\/ekiwi.de\/index.php\/1518\/html-navigation-mit-dropdown-und-javascript\/","title":{"rendered":"HTML-Navigation mit Dropdown und JavaScript"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Inhalt<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ekiwi.de\/index.php\/1518\/html-navigation-mit-dropdown-und-javascript\/#Videoanleitung\" >Videoanleitung<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ekiwi.de\/index.php\/1518\/html-navigation-mit-dropdown-und-javascript\/#Anleitung\" >Anleitung<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ekiwi.de\/index.php\/1518\/html-navigation-mit-dropdown-und-javascript\/#HTML-Code\" >HTML-Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ekiwi.de\/index.php\/1518\/html-navigation-mit-dropdown-und-javascript\/#Java-Script\" >Java-Script<\/a><\/li><\/ul><\/nav><\/div>\n<p>Eine kleine Navigation mit Target mittels Auswahlfeld und JavaScript. <\/p>\n<p><!--more--><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Videoanleitung\"><\/span>Videoanleitung<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/OERSI8dUWw8\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Anleitung\"><\/span>Anleitung<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In diesem Tutorial wollen wir uns eine kleine Navigation mittels eines Dropdown-Feldes anschauen. Bei Auswahl eines Elements soll eine bestimmte Seite ge\u00f6ffnet werden. Zus\u00e4tzlich wollen wir, dass wir festlegen k\u00f6nnen, ob wir die Seite in einem neuen Fenster \u00f6ffnen wollen.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/wp-content\/uploads\/2021\/03\/navi.png\" alt=\"\" width=\"375\" height=\"225\" class=\"alignnone size-full wp-image-1525\" srcset=\"\/wp-content\/uploads\/2021\/03\/navi.png 400w, \/wp-content\/uploads\/2021\/03\/navi-300x180.png 300w\" sizes=\"auto, (max-width: 375px) 100vw, 375px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"HTML-Code\"><\/span>HTML-Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Unser HTML-Code sieht so aus:<\/p>\n<pre>\r\n&lt;select name=&quot;testforen&quot; onchange=&quot;openNav(this.value);&quot;&gt;\r\n    &lt;option value=&quot;&quot;&gt;Biite Auswahl treffen&lt;\/option&gt;\r\n    &lt;option value=&quot;http:\/\/www.ekiwi.de|_blank\">eKiwi.de<\/option>\r\n    &lt;option value=&quot;http:\/\/www.da-software.net|_blank\">DA-Software.net<\/option>\r\n    &lt;option value=&quot;http:\/\/der-pranger.info\">Der-Pranger<\/option>\r\n    &lt;option value=&quot;http:\/\/ekiwi-blog.de\">eKiwi-Blog.de<\/option>\r\n&lt;\/select&gt;<\/pre>\n<p>Soweit ein normales Dropdown, die URL steckt im &#8222;value&#8220;, genauso wie das Ziel des Links, nach dem Link k\u00f6nnen wir mit | das Ziel abtrennen. Wird kein Ziel angegeben, wird der Link im gleichen Fenster oder Frame ge\u00f6ffnet. Bei Auswahl wird die Funktion &#8222;openNav&#8220; aufgerufen.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Java-Script\"><\/span>Java-Script<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Die Funktion &#8222;openNav&#8220;:<\/p>\n<pre>\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n    function openNav(s) {\r\n        let index = s.indexOf(&quot;|&quot;);\r\n        let url = s;\r\n        let target = &quot;_self&quot;;\r\n        if (index != -1) {\r\n            url = s.substring(0, index);\r\n            target = s.substring(index + 1);\r\n        }\r\n\r\n        if (url != &quot;&quot;) window.open(url, target);\r\n    }\r\n&lt;\/script&gt;<\/pre>\n<p>Hier lesen wir zuerst den Link aus, pr\u00fcfen ob ein Ziel abgegeben wurde und falls ja, dann extrahieren wir dies. Anschlie\u00dfend \u00f6ffnen wir den Link.<\/p>\n<p><a href=\"https:\/\/ekiwi.de\/tryit\/?id=153\" target=\"_blank\" rel=\"noopener\">Beispiel im Browser testen<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Eine kleine Navigation mit Target mittels Auswahlfeld und JavaScript.<\/p>\n","protected":false},"author":1,"featured_media":217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[5,15],"tags":[4,44],"class_list":["post-1518","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hmtl","category-javascript","tag-html","tag-javascript"],"_links":{"self":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/1518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/comments?post=1518"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/1518\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media\/217"}],"wp:attachment":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media?parent=1518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/categories?post=1518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/tags?post=1518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}