Home > Blockchain >  Direct link to a modal window doens't work
Direct link to a modal window doens't work

Time:07-11

For this webpage: https://www.wonderewereldvan.be/VakantieinBelgie/KalenderTest2.html I would like have a direct link to a modal popup.

Off course I searched Stackoverflow for possible solutions, and I tried several ones. However when using https://www.wonderewereldvan.be/VakantieinBelgie/KalenderTest2.html#myModal it doesnt't open the modal window.

The last piece of code I tried was

    function popModal() {
      // code to pop up modal dialog
    }

    var hash = window.location.hash;
    if (hash.substring(1) == 'myModal') {
      popModal();
    }

Those are the details of the popup:

<div  id="myModal">

Many thanks in advance for your help!

CodePudding user response:

You can put the existing code into an event handler named hashchange :

window.addEventListener("hashchange", () => {
  var hash = window.location.hash;
  if (hash.substring(1) == "myModal") {
    popModal();
  }
});

Read more about this handler in MDN hashchange

CodePudding user response:

Thank you! I tried this code, but it doesn't open the modal window yet.

Kind regards

  • Related