search

Home  >  Q&A  >  body text

After clicking the return button, the window pops up to close

<p>I'm trying to implement a feature where if a popup opens and the user cancels it and then presses the return key, it should not open the popup again but should go back to the previous page! </p> <p></p> <pre class="brush:php;toolbar:false;"><script> window.onload = function() { setTimeout(function() { window.open( "#popup_flight_travlDil3" ,"_self") }, 1000); } </script></pre></p>
P粉509383150P粉509383150457 days ago489

reply all(1)I'll reply

  • P粉458725040

    P粉4587250402023-08-30 11:53:53

    You can use sessionStorage

    window.addEventListener("DOMContentLoaded", function() { // or $(function() { ... in jQuery
      const popped = sessionStorage.getItem("popped");
      if (popped) return; 
      setTimeout(function() {
        window.open("#popup_flight_travlDil3", "_self")
        sessionStorage.setItem("popped",true)
      }, 1000);
    })
    

    reply
    0
  • Cancelreply