Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close fancybox from child window?

parent link:

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

jQuery code to initiate fancybox is...

$("#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 submit button is clicked i need to close fancy box in this page itself with jquery

i have tried using

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

But this doesn't work for me. If there is any option to close inside this ajax form please let me know.

like image 565
Mohan Ram Avatar asked Dec 08 '10 17:12

Mohan Ram


People also ask

How do I open Fancybox on button click?

on('click', function() { $. fancybox(); }); });


2 Answers

The following code should work, and has worked for many people

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

However, I have also seen, for instance in this question, jQuery being run in noConflict mode, unbeknownst to the user. If this is the case for you, you'd have to modify your script to

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

If none of those work, please use a tool like Firebug for Firefox, or the developer console for Chrome, to see if there is an error message, and report back to us what it is.

like image 99
David Hedlund Avatar answered Nov 04 '22 06:11

David Hedlund


Try

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

assuming that $.fancybox.close(); works in the parent window.

like image 34
Alin Purcaru Avatar answered Nov 04 '22 05:11

Alin Purcaru