example-dialog.htm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>jQuery Idle Timeout</title>
  5. <link href="examples.css" rel="stylesheet" type="text/css" />
  6. <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" rel="stylesheet" />
  7. <!-- we want to force people to click a button, so hide the close link in the toolbar -->
  8. <style type="text/css">a.ui-dialog-titlebar-close { display:none }</style>
  9. </head>
  10. <body>
  11. <div id="bar">
  12. <h1><a href="http://www.erichynds.com">eric<span>hynds</span></a></h1>
  13. </div>
  14. <!-- dialog window markup -->
  15. <div id="dialog" title="Your session is about to expire!">
  16. <p>
  17. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 50px 0;"></span>
  18. You will be logged off in <span id="dialog-countdown" style="font-weight:bold"></span> seconds.
  19. </p>
  20. <p>Do you want to continue your session?</p>
  21. </div>
  22. <div id="content">
  23. <h2>jQuery Idle Timeout Demo - jQuery UI Dialog</h2>
  24. <p>This idle timeout countdown is triggered after 5 seconds. <strong>Keep your mouse and keyboard still!</strong></p>
  25. <p>A polling request is sent to the server every two seconds to keep the server side session alive. I've set this parameter to an <em>extremely</em> low number
  26. for demo purposes (timeout is only 5 seconds), but in reality, this should be much higher.</p>
  27. <p>View source to see markup &amp; CSS.</p>
  28. <ul>
  29. <li><a href="example-mint.htm">View the original Mint.com example</a></li>
  30. <li><a href="http://github.com/ehynds/jquery-idle-timeout">Download &amp; follow on GitHub</a></li>
  31. <li><a href="http://www.erichynds.com">Return to home page</a>
  32. </ul>
  33. </div>
  34. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
  35. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
  36. <script src="src/jquery.idletimer.js" type="text/javascript"></script>
  37. <script src="src/jquery.idletimeout.js" type="text/javascript"></script>
  38. <script type="text/javascript">
  39. // setup the dialog
  40. $("#dialog").dialog({
  41. autoOpen: false,
  42. modal: true,
  43. width: 400,
  44. height: 200,
  45. closeOnEscape: false,
  46. draggable: false,
  47. resizable: false,
  48. buttons: {
  49. 'Yes, Keep Working': function(){
  50. $(this).dialog('close');
  51. },
  52. 'No, Logoff': function(){
  53. // fire whatever the configured onTimeout callback is.
  54. // using .call(this) keeps the default behavior of "this" being the warning
  55. // element (the dialog in this case) inside the callback.
  56. $.idleTimeout.options.onTimeout.call(this);
  57. }
  58. }
  59. });
  60. // cache a reference to the countdown element so we don't have to query the DOM for it on each ping.
  61. var $countdown = $("#dialog-countdown");
  62. // start the idle timer plugin
  63. $.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
  64. idleAfter: 5,
  65. pollingInterval: 2,
  66. keepAliveURL: 'keepalive.php',
  67. serverResponseEquals: 'OK',
  68. onTimeout: function(){
  69. window.location = "timeout.htm";
  70. },
  71. onIdle: function(){
  72. $(this).dialog("open");
  73. },
  74. onCountdown: function(counter){
  75. $countdown.html(counter); // update the counter
  76. }
  77. });
  78. </script>
  79. </body>
  80. </html>