Provide your feedback here JQuery code to run f...">

How to close fancybox from child window?

parent link:

<a href="feedback.php" id="feed">Provide your feedback here</a>

JQuery code to run fancybox ...

$("#feed").fancybox();

codes in feedback.php ...

      <html>
        <head>
<script language="javascript">    
$(document).ready(function(){
    $("#feed_submit").click(function(){
    //Name is alerted
    alert($("#name").val());

    //code to close fancy box(Not working)
    $.fancybox.close();

    });
    });
</script>
        </head>
        <body>
        <form method="post" name="feedback" id="feedback" action="">
                <div>
                    <label>name</label>
                    <input type="text" name="name" id="name"/>
                </div>
                <div>
                    <label>feedback</label>
                    <input type="text" name="content" id="content"/>
                </div>
        <div><input type="button" name="feed_submit" id="submit" value="submit"></div>
    </form>    
    </body>
    </html>

Once the submit button is clicked, I need to close the fancy box on this page using jquery

I tried to use

$.fancybox.close();
parent.$.fancybox.close();

But this does not work for me. If there is any way to close ajax inside this form, please let me know.

+5
source share
10 answers

The following code should work and worked for many people

parent.$.fn.fancybox.close();

However, I also saw, for example, in this question , jQuery runs in noConflict mode, without the knowledge of the user. If so, you will have to change your script to

parent.jQuery.fn.fancybox.close();

, Firebug Firefox Chrome, , , , .

+10

Try

window.parent.$.fancybox.close();

, , $.fancybox.close(); .

+7

Try:

$("#fancybox-close").trigger('click');
+2

fancybox iframe, iframe , jquery .. , - iframe, parent. $. fancybox.close()

, fancybox "iframe" , fancybox .

+1

, , , :

:

parent.jQuery.fancybox.close();

:

jQuery("#cancelId").click(function(){
    parent.jQuery.fancybox.close();
});

, , Naore

+1
$.fn.fancybox.close();

?

0

// iframe :

function closeIframe(){ parent.closeIframeMain(); }

// ,

<a onclick="closeIframe();" href="#">Close window</a>

// :

function closeIframeMain(){ jQuery("#fancybox-close").trigger("click"); }

0

, :

<a href="javascript:;" onclick="jQuery('.fancybox-close').fancybox().trigger('click');">Close from Inside</a>

, fancybox, .

:)

0

, ASP.NET.

, ( ) :

$.fancybox({
                href: '/ContactUs.aspx',
                type: 'iframe',
                padding: 60,
                width: 465,
                height: 670,
                maxWidth: 465,
                maxHeight: 670,
            });

When I click on the FancyBox, it works, but if I send it first, THEN close it fancyBoxwill not close, even if the page is in the same domain.

In the end, I found out that you should set autoSize: false when you open FancyBox:

 $.fancybox({
                href: '/ContactUs.aspx',
                type: 'iframe',
                padding: 60,
                width: 465,
                height: 670,
                maxWidth: 465,
                maxHeight: 670,
                autoSize: false
            });

Now it should work. Answer if this works for someone else. Greetings.

Will

0
source

parent.jQuery.fancybox.close (); with. $. - Shifts in IE8. With this - everything is fine.

-1
source

All Articles