简体   繁体   中英

how to close popup by clicking on iframe?

For any iframe I have, how do I get it to click anywhere in the iframe to close any popups that open from that iframe?

Something like:

<iframe id="iframe_id" src="https://somesite.com.br">

</iframe>


<script type="text/javascript">
    $('#iframe_id').on('click', function(event) { 
        close popups that have opened ...
    });

</script>

NOTE

I can't use sandbox = "allow-scripts" or other sandbox methods

your code:

<script type="text/javascript">
    $('#iframe_id').on('click', function(event) { 
        //code
    });

</script>

if those popups are in div then use this

<script type="text/javascript">
    $('#iframe_id').on('click', function(event) { 
        $('#iframe_id').find('div').remove();
    });

</script>

though it will remove all div contents if you don't want to include some div contents.

you can just change the div to any form of element if that popup have something in common.

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