1

Im new to Jquery Dialogs and Iframes and I just want to Ask if can i Refresh a Static Iframe when the Dialog Modal Closes.

Heres the Static Iframe:

                    <iframe id="frameUserInfo" src="/User/UserInfo" style="border: none; width: 100%;
                        min-height: 220px;"></iframe>
                </div>

And this is my Jquery Dialog

$("#dialogAddPhone").dialog({
            autoOpen: false,
            resizable: false,
            modal: true,
            width: 700,
            height: 700,
            position: ['center', 40],
            close: function (event, ui) {
                $('#dialogAddPhone').attr('src', '');
            }
        });

I Tried adding This $('#frameUserInfo').reload(true); but its not working

just want to give you a better picture, In my Parent window, theres a static Iframe that contains a button that opens the $("#dialogAddPhone") the click event is being called at /User/UserInfo

This one is in the Parent Window:

<div id="dialogAddPhone" title="Document Upload" style="overflow-y: hidden;">
    <iframe id="myIframeAddPhone" src="" style="border: none; width: 100%; height: 100%;">
    </iframe>
</div>

Then this is the Open Event in the Static IFrame in User/UserInfo

loadIframe('myIframeAddPhone', href);
 parent.$("#dialogAddPhone").dialog("open");
 return false;

Then after Closing the Dialog , it should refresh the Iframe only of the frameUserInfo

Thanks! :)

Ren Tao
  • 397
  • 2
  • 10
  • 25

2 Answers2

1

You can use the following :

First Method:

$("#dialogAddPhone").dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        width: 700,
        height: 700,
        position: ['center', 40],
        close: function (event, ui) {
            $('#dialogAddPhone').attr('src', '');
            document.getElementById('frameUserInfo').contentWindow.location.reload(); //Reloads the Iframe
        }
    });

Second Method:

Set the source of iframe again. It will refresh the iframe.

$("#dialogAddPhone").dialog({
    autoOpen: false,
    resizable: false,
    modal: true,
    width: 700,
    height: 700,
    position: ['center', 40],
    close: function (event, ui) {
        $('#dialogAddPhone').attr('src', '');
        var iframe = document.getElementById('frameUserInfo');
        iframe.src = iframe.src;//Reloads the Iframe
    }
});

The first method wont work in Chrome as there is no contentWindow property. So you should go with the second method.

Here is a Demo for the same using second method.

Senjuti Mahapatra
  • 2,570
  • 4
  • 27
  • 38
0

Try this:

$( '#frameUserInfo' ).attr( 'src', function ( i, val ) { return val; });

Link: https://stackoverflow.com/a/4249946/2848607

Community
  • 1
  • 1
Shayou
  • 19
  • 3