Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7090983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:07:30+00:00 2026-05-28T08:07:30+00:00

I have a jQuery modal dialog with an iFrame in it that shows some

  • 0

I have a jQuery modal dialog with an iFrame in it that shows some content. When a user selects an option in the iFrame, I make an Ajax call, and then I want to close my dialog, however it is not closing for me.

On my parent form I have a div tag:

div id="structureDialog" title="Add Structure"

I open my dialog when the user clicks an element on the parent:

// bind an onclick event onto tiles to display the modal dialogue window
$(".stationTile").bind('click', function () {
    var src = "<iframe src="myurl" />";
    var locationID = 1;
    $("#structureDialog").attr("locationID", locationID);
    $("#structureDialog").html(src);  //iframe
    $("#structureDialog").dialog({
        modal: true,               
    });    
});

In my iFrame I have the following:

$(".userOption").bind('click', function () {
    $.ajax({
        async: false,
        type: "POST",
        url: "/NewStructure.aspx/Build",   
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: buildSuccess
    });
});

function buildSuccess(res, dest) {
    $("body", window.parent.document).attr("style", "background-color:yellow;");
    $("#structureDialog", window.parent.document).attr("style", "background-color:red;");
    $("#structureDialog", window.parent.document).dialog('close');
}

In my function buildSuccess, I am able to successfully change my dialog box to red. However, the close function will not close my dialog box. From most examples I have seen so far, this code should work fine, so I’m stumped.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:07:31+00:00Added an answer on May 28, 2026 at 8:07 am

    As I wrote in the comment above, the solution is related to the instance of jquery being run. When the dialog object is created, it is in the context of the jquery instance of the parent form. In an iFrame, a second instance of jquery is created, and hence the dialog box is not in scope.

    Calling $("#structureDialog", window.parent.document).dialog('close'); searches the DOM of the parent using the local instance of jquery, and so since the dialog box was not initialized there, it cannot be closed there.

    The solution is to reference the jquery instance of the parent by rearranging the terms as follows:

    parent.$("#structureDialog").dialog('close');

    This points the context to the parent first, and then uses the jquery instance of the parent to find the dialog box and close it.

    Kudos to chrismarx1 on this post which pointed me to this solution:
    http://forum.jquery.com/topic/trigger-from-iframe-to-parent-window

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery modal dialog that loads a different page on an iframe.
i have a modal popup built with jquery UI ($.dialog) that contains an iframe
I have a modal dialog plugin written in jquery, that binds to the click
I am using jQuery UI dialog for modal popups. I have some iframes in
I have a textarea element inside of a jquery modal dialog that has an
I have setup a jQuery UI modal dialog to display when a user clicks
I have a very basic jquery mobile modal dialog that INTERMITTENTLY reloads on clicking
I have a jquery-ui modal popup that contains an iframe. It is called as
My Needs: I am using a jquery modal dialog. I have some buttons on
I have a jQuery UI modal dialog, and it shows up right. Then, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.