Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a 8 iframe popups in one page and use this code to close iframe forcefull
but its work only in 1 or 2 popup and other not close on escape key

C#
$("#VendorframeID").ready(function () {
        setTimeout(function () {
            $('#VendorframeID').contents().find('body').keyup(function (e) {
                if (e.keyCode == 27) {
                    $("#ShowVendor").modal("hide");
                }
            });
        }, 150);
    });

i use iframe id and its
tag id for close iframe in all frame popup lke above example
give me a soution
Posted
Comments
Manish Dalwadi 8-Dec-14 23:32pm    
i use iframe id and its
div tag id for close iframe in all frame popup lke above example
give me a soution
mudgilsks 8-Dec-14 23:48pm    
is able to get the concern popup
id
Ishpreet Kaur 8-Dec-14 23:52pm    
can you post your html?
Manish Dalwadi 9-Dec-14 0:26am    
<div class="modal bootstrap-dialog type-primary" id="ShowVendor" tabindex="-1">
<div class="modal-dialog" style="width: 90%;">
<div class="modal-content">
<div class="modal-header">
<div class="bootstrap-dialog-header">
<span class="glyphicon glyphicon-remove"></span>

</div>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<iframe id="VendorframeID" name="VendorframeID" src="/vendor/IframeVendorlist/?isIframetype=search" style="width: 100%; min-height: 500px;"></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
Ishpreet Kaur 8-Dec-14 23:55pm    
You have used id to refer to iframe. Id is unique and only works for one HTML element. Thats why, only first is closed on escape key press. Use class if want to close multiple iframes at the same time.

1 solution

XML
<html>
<head>
<script type="text/javascript">
    function a(event)
    {
        alert(event.keyCode);
        if(event.keyCode==27)
        {
            // OPTION 1 : START

            document.getElementById("1").style.display="none";
            document.getElementById("2").style.display="none";
            document.getElementById("3").style.display="none";

            document.getElementById("4").style.display="none";
            document.getElementById("5").style.display="none";
            document.getElementById("6").style.display="none";

            document.getElementById("7").style.display="none";
            document.getElementById("8").style.display="none";

            // OPTION 1 : END



            // OPTION 2 : START

            for(var k=1;k<=8;k++)
            {
                document.getElementById(k).style.display="none";
            }

            // OPTION 2 : END
        }
    }
</script>
</head>
<body onKeyUp="a(event);" id="bd">
        <iframe id="1"></iframe>
        <iframe id="2"></iframe>

        <iframe id="3"></iframe>
        <iframe id="4"></iframe>

        <iframe id="5"></iframe>
        <iframe id="6"></iframe>

        <iframe id="7"></iframe>
        <iframe id="8"></iframe>
</body>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900