javascript - Hide iFrame when you click anywhere outside its boundaries -


im looking iframe close when click away it.

i have tried jquery unsuccessful:

$('body').click(function(event){  if($(event.target).parents('#mainframe_example').length <= 0)      $('#mainframe_example').hide(); }) 

heres code:

<div class="modal-content">       <div class="modal-header">         <h4 class="modal-title generic-modal-title">select</h4>       </div>       <div class="modal-body generic-modal-body">         <div style="max-height:400px; overflow:scroll;">             <iframe src="blahblahblah.aspx" id="mainframe_example" width="100%" height="400px" scrolling="no" frameborder="0"></iframe>         </div>        </div> </div> 

does have ideas?

try this:

$(document).add(parent.document).click(function(e) {     var iframe = $('iframe');     if (!iframe.is(e.target) && iframe.has(e.target).length === 0) {         iframe.hide();     } }); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -