The site has modalki. Called via uikit 2.25 - UIkit.modal (). I need to add a window id to the url when I call it. The console is clean. No errors fall out. I can not understand where the error is. Why does not it work?
let isChangingModal = false; window.addEventListener("load", ()=>{ for (let modal of document.querySelectorAll("[data-popup]")) { modal.addEventListener("beforeshow", ()=>{ isChangingModal = true; window.location.hash = "#" + modal.getAttribute("data-popup"); }); modal.addEventListener("beforehide", ()=>{ isChangingModal = true; window.location.hash = "#"; }); } showModalFromURL(); }); function showModalFromURL() { if (isChangingModal) { isChangingModal = false; return; } let modal = document.querySelector(`[data-popup="${window.location.hash.slice(1)}"]`); if (modal) { UIkit.modal(modal).show(); } } window.onhashchange = showModalFromURL;
<head> <meta charset="utf-8"> <title>test</title> <!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.3/css/uikit.min.css" />--> <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.3/js/uikit.min.js"></script> --> <!--<script src="http://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>--> <script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.25.0/css/uikit.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.25.0/js/uikit.min.js"></script> </head> <body> <p style="text-align: center;"><button class="uk-button uk-button-large uk-button-danger" data-uk-modal="{target:'#my-id2081'}">Подробнее</button></p> <div id="my-id2081" class="uk-modal" data-popup="test"> <div class="uk-modal-dialog"> <a class="uk-modal-close uk-close"></a> <br>Милые дамы! </br> <br>Не пропустите!<b> Набор в мини-группу "Богемская растяжка"!</b></br> <br>Богемский интенсив для тех, кто не боится окунуться в мир приятной (и не очень) боли, криков, стонов, устранения закрепощенности и зажимов в мышцах, да-да, всё это о растяжке! А вы о чем подумали? :)</br> <a class="uk-button uk-button-primary" href="kupit-kartu ">Узнать стоимость карты</a> </div> </div> </body>
On a separate page you can see here http://test.endlesstest.ru
beforeshow
is caused? - Stepan Kasyanenko Feb. 5:24 pmUIkit
like. - Stepan Kasyanenko Feb.