0

I have a simple jQuery UI Dialog. Everything is working as expected when viewing the page by itself except when that page is in an iframe. For some reason the close: function isn't firing.

Everything is working when viewing the page by itself; the open: function triggers normally inside the iframe; however, the close: function will not fire.

The hide: doesn't seem to be working either, dialog stays open and won't close or run the close: function. again it's only doing it when have to load that page in an iframe.

Is there anything about the dialog and iframes that would be causing this problem? They are also using the datatables plugin so they can sort the table and whatnot. Would this cause a problem?

Tried finding an answer but nothing was coming up like this

//jQuery UI: v1.12.1
//jQuery DataTables: v1.10.13
//jQuery: v1.12.4 (they're don't want to update, but temporary loaded v3.7.1 with same result)
//Firefox, Firefox developer, and Chrome lastest versions

$('#popupDialog').dialog({
    autoOpen: false,
    height: 'initial',
    width: 'initial',
    show: {
        effect: 'slide',
        duration: 500
    },
    hide: {
        effect: 'transfer',
        to: '#logo2',
        className: 'ui-effects-transfer',
        duration: 500
    },
    modal: true,
    open: function() {
        alert('ttt');
    },
    close: function() {
        alert('rrr');
    }
});
2
  • What Libraries are loading in the iFrame source? Commented Jul 31, 2024 at 16:02
  • just the ones listed, jQuery is the only thing from vanilla JS used on all their pages Commented Jul 31, 2024 at 17:02

1 Answer 1

0

Your code appears to work in an iFrame:

https://jsfiddle.net/Twisty/qhe0L1an/

JavaScript

$(function() {
  var $html = $("<html>");
  $("<head>").appendTo($html);
  $("<link>", {
    rel: "stylesheet",
    href: "https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"
  }).appendTo($("head", $html));
  $("<script>", {
    src: "https://code.jquery.com/jquery-1.12.4.js"
  }).appendTo($("head", $html));
  $("<script>", {
    src: "https://code.jquery.com/ui/1.12.1/jquery-ui.js"
  }).appendTo($("head", $html));
  $("<body>").appendTo($html);
  $("<div>", {
    id: 'popupDialog',
    title: "Test Dialog"
  }).html("<p>My Dialog</p>").appendTo($("body", $html));
  $("<button>", {
    id: "openDiag",
  }).html("Open").appendTo($("body", $html));
  $("<script>").text("console.log('Loading Script in iFrame'); $('#popupDialog').dialog({ autoOpen: false, height: 'initial', width: 'initial', show: { effect: 'slide', duration: 500 }, hide: { effect: 'transfer', to: '#logo2', className: 'ui-effects-transfer', duration: 500 }, modal: true, open: function() { console.log('ttt'); }, close: function() { console.log('rrr'); } }); $('#openDiag').click(function(){ $('#popupDialog').dialog('open'); })").appendTo($("body", $html));

  var $iframe = $("<iframe>").css({
    width: "100%",
    height: "380px"
  }).attr("srcdoc", $html.prop("outerHTML")).appendTo("body");
});

Most of the code is just building the HTML and iFrame structure. When you run JS/jQuery in a Frame, the library must be loaded with it. If it is loaded in the parent, the Frame will not have access to those libraries.

Sign up to request clarification or add additional context in comments.

1 Comment

double checked, the libraries are loaded in the iframe. But your fiddle gave me an "can't access property "top", endPosition is undefined" error that I wasn't getting for some reason. Somebody changed the case on the target logo div ID so it was erroring out with the hide: parameter. Changed that parameter to match and it's working correctly now. Thank you for the help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.