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?

6 Answers 6


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, 2012 at 23:25
  • 1
    This worked perfectly.
    – user5907
    May 10, 2012 at 21:41

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) {
  • 2
    Unfortunately this is not supported by all browsers.
    – Christophe
    May 9, 2012 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 May 10, 2012 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, 2012 at 15:17
  • IE8 is the current supported browser.
    – user5907
    May 10, 2012 at 20:58

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):


  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.


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.


Here's what I use:

var currUrl = document.location.toString().toUpperCase();
var isDlg = GetUrlKeyValue('ISDLG', false, currUrl, true);
if(isDlg == 1){
    //form is in a dialog
    //not in a dialog
// How to check if modal window is opened - 
SP.UI.ModalDialog.get_childDialog() ? console.log('modal') : console.log('no modal');

Your Answer

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