简体   繁体   中英

opening jquery modal dialog on page load

Clicking save is opened dialog JQUERY UI

$('#save_project').load('dialog/save_project.php').dialog({ autoOpen: false, modal:true });

    $('#save').click(
        function () {
            $('#save_project').dialog('open');
            return false;
        }
    );

<a id="save">Open</a>
<div id="save_project" title="Dialog">
</div>

There is button type submit into dialog. After clicking the button page is redirected to the page go.php and returns to index.php. My question is that how can I show this dialog again while returning to index.php?

To be able to only on initial load not open the modal, the code on subsequent pages must be aware of the fact that this is no longer initial page (even though the same page was opened). For that, you must use the session or pass around information as request parameters, like this mockup "index.php":

<html>
<body>
  <div id="save_project" title="Dialog"></div>
  <a id="save">Open</a>
  <script type="text/javascript" src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
  <script type="text/javascript" src="http://codeorigin.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
  <script>
  function getURLParameter(name) {
    return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
  }

  var openModal = getURLParameter("openModal");

  $('#save_project').load('dialog/save_project.php').dialog({ autoOpen: (openModal != "null"), modal:true });
  $('#save').click(
    function () {
      $('#save_project').dialog('open');
      return false;
    }
    );
  </script>
</body>
</html>

When returning to the index.php from subsequent pages, just pass ?openModal=true .

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