Advertisement
Guest User

Untitled

a guest
May 25th, 2022
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. /* Close canva menu when try back previous page  */
  2. function back_button_close_menu_f() {
  3.     echo' <script>
  4.    
  5.     const canva_menu = document.querySelector("#generate-slideout-menu");
  6.    
  7.     if (window.history && window.history.pushState){
  8.         window.addEventListener("popstate", function(e){
  9.            
  10.             // Verify if menu is open
  11.             if ( canva_menu.classList.contains("is-open") ){
  12.                 // close menu
  13.                 var botoes = document.querySelectorAll("button.slideout-exit");
  14.                 for (var i = 0; i < botoes.length; i++){
  15.                     botoes[i].click();
  16.                 }
  17.                 e.stopPropagation();
  18.             }
  19.         }, false);
  20.     }
  21.  
  22.     </script> ';
  23. }
  24. add_action('wp_footer', 'back_button_close_menu_f');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement