简体   繁体   中英

How to open external stored modal on page load

I have a modal for signing in user and would like to show it automatically on special pages if the user is not logged in. The modal is stored in an external file (modal_sign_in.php) so that I can call it from different pages.

Code of the link in menu bar:

<a href="" id="modal_sign_in" data-modal-external-file="modal_sign_in.php"
data-target="modal_sign_in" class="promoted">Login Modal</a>

How can I display the modal from any page on load checking if the user is logged in?

if ( $_SESSION['logged_in'] != 1 ) {       
    ??????
    exit();
}

You simply include that external file in there :

if ( isset($_SESSION['logged_in']) {   
  if ( $_SESSION['logged_in'] != 1 ) {           
    include("modal.php");
  }
}

If the modal does not trigger automaticly , you ill need to trigger it, with javascript. Create a button, change visibility to hidden, then connect that btn to the modal, and then you trigger the click.

if ( $_SESSION['logged_in'] != 1 ) {       
    include("modal.php");
    echo "<script> $( '#yourbtnid' ).trigger( 'click' ); </script> ";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM