views:

14633

answers:

10

I've been using Simple Modal and i feel it doesn't live up to what i need at the moment.

Is there a Modal Box that supports loading external files and allows those external files to close the modal box and redirect the parent page to some url.

An example of what i want to do. You have a list of users, you could click "Add user" and a Modal Box with the form pops up, you fill that in and submit it. That would close the box and reload the user list page so you would see the user in the list.

Then you could click "Edit user" and a Modal Box with the user info filled in the form fields would pop up and you could edit, submit and it would close and refresh.

I know this can be done if i have the user info form as a hidden div for each user but this will not scale well and it is a lot of overhead data.

I found some code about this on Google Code but just can't get it to work (possibly different simple modal version

I am willing to change to another modal box tool also.

UPDATE:

Do either Thickbox or Fancybox support being closed from a child IFrame element?

A: 

Have you tried ThickBox ?

mathieu
+2  A: 

Fancybox is also another option. Works similarly to Thickbox

EDIT:

It appears after some playing around that the plugin does not natively support closing the Fancybox through an child iframe element. I think that this is certainly achievable with a little effort (I started hacking together something here, although I stress that this was simply a POC and does not work as the button within the iframe removes the fancybox div wrapper from the DOM and therefore does not display when you click the google image again).I am wondering however, if an iframe is the right lines to go down.

For adding a user, my thought would be that you could present the user with a modal form like the one on the Monster site you get when you click 'Sign In.' Once you click add user, make an AJAX call to your datasource to insert a new user and then on returning success, you could either initiate a page refresh or use AJAX to update the list.

For editing a user, once a user is selected, you could make an AJAX call with a user id to populate a modal form with the user details retrieved from your data source when the AJAX call returns success. Once you have finished editing the user, make an AJAX call to update your datasource and then again, initiate a page refresh or use AJAX to update the list.

Instead of the page refresh or final AJAX call in each scenario, you could simply use JavaScript/jQuery to update the list/ list details, depending on whether a user has been added or edited, respectively.

Russ Cam
I really appreciate your effort on this and your idea to use AJAX will probably get me pretty far into what i want. I'm going to check it out at work tomorrow and ill update my question when i find something. Thanks again.
Ólafur Waage
A: 

I have found the solution for me, it's using nyroModal. It supports iframes and closing of the modal through its iframe child with this code.

parent.$.nyroModalRemove();

I am going to accept Russ Cam's answer to give him more rep since his reply made me think a lot about how this is going to work and eventually made me find the answer.

Ólafur Waage
Thank You :) Funnily enough, I started playing with closing the Fancybox through an iframe child element by calling the fancybox close function and got that working. I'm glad you found a solution. Do you have a link for nyroModal?
Russ Cam
I sure do. http://nyromodal.nyrodev.com/
Ólafur Waage
+4  A: 

Sounds like you already found the answer but for the benefit of others you can close an iFrame implementation of FancyBox by using the following JavaScript in the iFrame:

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

Blegger
A: 

Nice last post: parent.$.fn.fancybox.close(); work for me !!! (se also: http://groups.google.com/group/fancybox/browse_thread/thread/a6eaf87875b93829 )

Thanks A LOT !

A: 

wonderful help! One thing is missing for me: How can I send the post-request to the page, I want to?

For example: When form.php is submitted I would like it to submit to the parent window not stay within the lightbox window.

Any help would be greatly appreciated.

As far as I know you can't send a post request from one window instance to another.
Ólafur Waage
+1  A: 

parent.$.modal.close(); works for simple modal plugin.

A: 

Below is a basic dialog interaction loading content into an iFrame and then closing the dialog from the iFrame.

Note that to illustrate this I have two code snippets. The first is labeled file1.html. The second you should name "myPage.html" if you want it to work and place it in the same directory as the first file.

Note that the call to close the dialog could be used in other ways depending on your desired functionality. For example another example could be on successful form submission.

Create the files locally on your system and open file1.html and try it out.

file1.html

<html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"&gt;&lt;/script&gt;
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/&gt;
    <script type="text/javascript">
      $(document).ready(function() {
            $("#modalDiv").dialog({
                modal: true,
                autoOpen: false,
                height: '180',
                width: '320',
                draggable: true,
                resizeable: true,   
                title: 'IFrame Modal Dialog'
            });
            $('#goToMyPage').click(
                function() {
                    url = 'myPage.html';
                    $("#modalDiv").dialog("open");
                    $("#modalIFrame").attr('src',url);
                    return false;
            });                 
      });
    </script>
    </head>
    <body>
        <a id="goToMyPage" href="#">Go to My Page</a>
        <div id="modalDiv"><iframe id="modalIFrame" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" title="Dialog Title"></iframe></div>
    </body>
</html>

myPage.html

<html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"&gt;&lt;/script&gt;
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/&gt;
    <script type="text/javascript">
        $(document).ready(function() {
            $('#clickToClose').click(
                function() {
                    window.parent.$("#modalDiv").dialog('close');
                    return false;
            });
            // uncomment and use the below line close when document is ready (no click action by user needed)
            // the same call could be put elsewhere depending on desired functionality (after successful form submit, etc.)
            // window.parent.$("#modalDiv").dialog('close');                    
        });
    </script>
    </head>
    <body>
        <a id="clickToClose" href="#">Click to close.</a>
    </body>
</html>
Josh Metcalfe
A: 

My FrameDialog will allow for this, it basically extends on the Dialog... if you're using the same domain, you should be able to call $.FrameDialog.close() though, if you're redirecting, you can simply redirect the parent. window.parent.location will do.

http://plugins.jquery.com/project/jquery-framedialog

Tracker1
A: 

HI, Anyone who is having trouble closing a Fancy Box iFrame using a manual install of Fancy Box in Wordpress 3.0:

Use this link in your iframe:

<a href="#" onClick="parent.jQuery.fancybox.close();" title="Close window">close fancybox</a>

It works :)

dave