6

Is there a way to detect using sp.js or jquery to detect if the current context is in a modal dialog box?

Im not sure I explained that right, so here is a situation:

We have a branded system master page due to some front facing blogs and list views so one of our requirements is to have it look exactly like the branded custom masterpage. Now, due to the styling applied to the system masterpage, the modal dialog boxes for actions like creating a new page are messed up.

Looking at the source, it looks like an iframe is used inside the modal dialog box, so its opening up a new window. My intention is to have a jquery function detect if the current page is a modal dialog box, and if it is, register a new css to override the styles to make the dialog box look normal. Is this possible?

15

Try this:

if (window.location.search.match("[?&]IsDlg=1"))
  • 1
    +1 I think that's exactly what the OP needs - a way to identify when SharePoint tweaks the page style, iframe or not. – Christophe May 9 '12 at 23:25
  • 1
    This worked perfectly. – John S May 10 '12 at 21:41
4

When in Dialog mode the window.frameElement is NEVER null. use this as example on how to close it remotely

var parentObject = window.frameElement;
    if (parentObject != null) {
        var waitDialog = parentObject.waitDialog;
        if (waitDialog != null) {
            waitDialog.close();
        }
    }
  • 2
    Unfortunately this is not supported by all browsers. – Christophe May 9 '12 at 23:08
  • to my knowledge it is supported by modern browsers, such as IE/FF/Mozzila/Safari, have a look here help.dottoro.com/ljsokerh.php – Marius Constantinescu - MVP May 10 '12 at 14:08
  • I couldn't find a good reference. All recent versions of IE should be fine. Not so sure about Chrome and Safari. – Christophe May 10 '12 at 15:17
  • IE8 is the current supported browser. – John S May 10 '12 at 20:58
4

I have added my comments to the above answers. Here are a couple additional - untested - suggestions:

  1. To build on Steve's suggestion, reload the url without IsDlg (simple, just not ideal from a performance viewpoint):

    window.location.href=window.location.href.replace(/[?&]IsDlg=1/,"");

  2. SharePoint uses the class s4-notdlg to identify what should be hidden in a modal dialog. Use css or jQuery to overwrite or remove this class.

3

You could simply use javascript to identify if the page is loaded in an iframe: http://www.24hourapps.com/2009/01/check-if-page-is-loaded-in-iframe-using.html

var isInIFrame = (window.location != window.parent.location) ? true : false;

SharePoint dialog boxes are simply iframes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.