I have a website, that uses an iframe. The iframe itself is the content of the website. Now in the iframe I would like to use the jQuery Dialog. However when using it, the overlay and dialog is only displayed inside the iframe not on the parent. My parent html has the following html defined for the dialog:
<div id="modalHolder"></div>
In my iframe I am using the following javascript to create the dialog and to show it.
dlg1 = $(window.parent.document.getElementById("modalHolder"));
dlg1 = dlg1.dialog({
width: 300,
height: 150,
modal: true,
autoOpen: false,
resizable: false,
closeOnEscape: false,
draggable: false,
overlay:
{
backgroundColor: 'red',
opacity: 0.65
},
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); }
});
To show the dialog I use this:
dlg1.dialog('open');
A dialog box is a floating window with a title and content area. This window can be moved, resized, and of course, closed using "X" icon by default. jQueryUI provides dialog() method that transforms the HTML code written on the page into HTML code to display a dialog box.
As the jQuery object is attached to the parent's window object, I call parentWindow.$ to query the DOM of the parent web page. I send a query to parentWindow.$ to look for the HTML element with messagesArea as its id, and remember it as $messagesArea.
The basic dialog window is an overlay positioned within the viewport and is protected from page content (like select elements) shining through with an iframe. It has a title bar and a content area, and can be moved, resized and closed with the 'x' icon by default. < p > This is the default dialog which is useful for displaying information.
The basic dialog window is an overlay positioned within the viewport and is protected from page content (like select elements) shining through with an iframe. It has a title bar and a content area, and can be moved, resized and closed with the 'x' icon by default.
There is simple and graceful solution:
For example:
var $jParent = window.parent.jQuery.noConflict();
var dlg1 = $jParent('#modalHolder');
dlg1.dialog();
Because the dialog function is running within the context of the iframe, it will always create the dialog divs (like the semi transparent background div and the dialog div) as children of the iframe's . Even though you're grabbing the element from the parent document, the actual script is still running in the iframe. If you have Firefox and Firebug, you should be able to use the HTML inspector to see what's going on.
I can only think of two solutions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With