JQuery: Click anywhere on body to close modal dialog for this code -


the same question asked here. doesn't state source, , solution given not directly applicable in case afaik. might modded down this, asking anyway. my entire code:

<html><head>     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>     <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/humanity/jquery-ui.css" type="text/css" />     </head>     <body><div id="dialog" title="title box">         <p>stuff here</p>     </div>     <script type="text/javascript">       jquery(document).ready(function() {         jquery("#dialog").dialog({           bgiframe: true, autoopen: false, height: 100, modal: true         });       });     </script>     <a href="#" onclick="jquery('#dialog').dialog('open'); return false">click view</a> </body></html>   

all script files third party hosted, , want keep way.

how "click anywhere (outside box)to close modal box" functionality?

<html>  <head>   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>   <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/humanity/jquery-ui.css" type="text/css" />  </head>  <body>   <div id="dialog" title="title box">    <p>stuff here</p>   </div>   <script type="text/javascript">    jquery(     function() {      jquery("#dialog")       .dialog(        {         bgiframe: true,         autoopen: false,         height: 100,         modal: true        }       );      jquery('body')       .bind(        'click',        function(e){         if(          jquery('#dialog').dialog('isopen')          && !jquery(e.target).is('.ui-dialog, a')          && !jquery(e.target).closest('.ui-dialog').length         ){          jquery('#dialog').dialog('close');         }        }       );     }    );   </script>   <a href="#" onclick="jquery('#dialog').dialog('open'); return false">click view</a>  </body> </html> 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -