I'm trying to make a jQuery modal dialog box that covers the entire webpage. It works fine on some sites but not on others. The problems I'm having are that the dialog box is underneath webpage content, like the google search bar and button, and the modal overlay does not cover the entire page. Here both the dialog box and overlay are covered by the upper Google banner
Here is my code. I'm using the dialog box like an alert in a chrome extension so everything has to be in a content script that background.js executes.
if (someEvent) {
var NewDialog = $('<div id="MenuDialog"><p>This is dialog content.</p></div>');
NewDialog.dialog({
autoOpen: false,
modal: true,
title: "title",
zIndex: 99999,
buttons: [
{text: "Submit", click: function() {doSomething()}},
{text: "Cancel", click: function() {$(this).dialog("close")}}
]
})
NewDialog.dialog("open");
});
}
I've looked all over for solutions including changing the z indices but nothing seems to work. What's the best way to do it?
Update
I'm trying the iframe approach suggested by Veritoanimus but I'm still stuck. I found code that creates an iframe over an entire page, so it works like a modal. But how do I add the dialog box to the iframe?
Code:
wrapperDiv = document.createElement("div");
wrapperDiv.setAttribute("style","position: absolute; left: 0px; top: 0px; background-color: rgb(255, 255, 255); opacity: 0.5; z-index: 2000; height: 1083px; width: 100%;");
iframeElement = document.createElement("iframe");
iframeElement.setAttribute("style","width: 100%; height: 100%;");
wrapperDiv.appendChild(iframeElement);
document.body.appendChild(wrapperDiv);
var newDiv = $(document.createElement('div'));
newDiv.html('hello there');
newDiv.dialog({
title: "title",
zIndex: 99999,
buttons: [
{text: "Submit", click: function() {doSomething()}},
{text: "Cancel", click: function() {$(this).dialog("close")}}
]
})
This is what it looks like. I know it's the same issue because I'm not really doing anything different with the dialog, but I can't figure out how to work the two together.