#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

How to show a pop-up in SharePoint

koskila
Reading Time 6 min
Word Count 1025 words
Comments 16 comments
Rating 4.3 (4 votes)
View

This ages-old trick deserves to be published - since it makes it easy to quickly show info from pretty much any other page on pretty much any Classic SharePoint page (in a SharePoint-compatible pop-up). So, here goes:

Using SharePoint's JavaScript library to open an arbitrary pop-up

Yes - SharePoint contains all the functionality out-of-the-box, and you almost don't have to do anything yourself! Let's see how this works.

Okay - long story short. On all Classic SharePoint pages, you can call this function: SP.UI.ModalDialog.ShowPopupDialog(). Like it says, it quite simply just opens a pop-up dialog, showing the page that it finds from the URL.

See below for a simple example:

<!-- Opens a pop-up -->
<a onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('https://yourtenant.sharepoint.com/sites/intranet/Pages/default.aspx')">Show more!</a>

What's cool about this, is that you can show pretty much any page (that allows it) in this pop-up! For an example, see below.

Showing a page from my blog in a pop-up on a Classic SharePoint site

 Showing a page from my website/blog in a pop-up on a Classic SharePoint site... It looks fairly good, and it's EASY!

This works in SharePoint Online, SharePoint 2010, SharePoint 2013, SharePoint 2016, and even SharePoint 2019... As long as you're using Classic SharePoint, you should be good! The best part is that it's ridiculously easy.

How to show SharePoint pages in pop-ups?

But let's imagine a different use case - showing another SharePoint page in a pop-up. You can use the same function for that!

This is very useful for showing other SharePoint pages in the context of whatever page the user is currently browsing. For example, this could look something like this:

Out-of-the-box SharePoint site in a pop-up might scale erratically

 Out-of-the-box SharePoint site in a pop-up might scale erratically

As you can probably imagine, showing just "any" page in SharePoint in a pop-up might also cause weird layout issues. This is especially true with out-of-the-box SharePoint sites, that is not responsive - they won't always play nice in a pop-up! Luckily, the code for showing that pop-up appends the ?IsDlg=1 to the URL of the page, to hide the chrome of the page. That makes the page act a lot nicer.

If this doesn't work for whatever reasons, you should modify the URL you're passing to the method to include "IsDlg=1" as a parameter. See this post for more details:

https://www.koskila.net/how-to-show-a-classic-sharepoint-page-in-dialog-mode-without-sharepoints-full-blown-chrome/

The following script example shows how to use this:

<!-- Opens a pop-->
<a onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('https://yourtenant.sharepoint.com/sites/intranet/Pages/default.aspx?IsDlg=1')">Show more!</a>

Showing responsive SharePoint pages in pop-ups

However, if you're using responsive styles in your SharePoint site, it might work reasonably well (even though the pop-up is going to be pretty cramped). Below, there's a decent example of that:

The example is from a development environment, with responsive layout - so the pop-up contents actually scale fairly well!

The example is from a development environment, with a responsive layout - so the pop-up contents actually scale fairly well!

One thing to note, however, is that you customize the size of the pop-up to offer more space for the contents. To achieve this, you'll have to change the method call you're using, though!

Next, let's take a look into how to do that...

How to customize the pop-up in SharePoint?

You can actually tweak how the pop-up works in quite a few different ways. If you call .showModalDialog() instead of .ShowPopupDialog() (it's interesting that Microsoft decided to deviate from camelCase there!), you can replace the "URL" property (basically just the URL as a string) in the method call with an object containing any of the following properties. Only the "URL" or "HTML" property is required, everything else is optional.

Below, I've gathered the different configuration values you can pass on to the function. You'll need to add them as additional properties for the "options" object - let's see how that works!

Documentation of .showModalDialog()'s options:

"options" object's properties Description
title A string that contains the title of the dialog.
URL A string that contains the URL of the page that appears in the dialog. If both URL and HTML are specified, the URL takes precedence. Either URL or HTML must be specified.
HTML A string that contains the HTML of the page that appears in the dialog. If both HTML and URL are specified, the URL takes precedence. Either URL or HTML must be specified.
x An integer value that specifies the x-offset of the dialog. This value works like the CSS left value.
y An integer value that specifies the y-offset of the dialog. This value works like the CSS top value.
width An integer value that specifies the width of the dialog. If width is not specified, the width of the dialog is autosized by default. If the autosize is false, the width of the dialog is set to 768 pixels.
height An integer value that specifies the height of the dialog. If the height is not specified, the height of the dialog is autosized by default. If the autosize is false, the dialog height is set to 576 pixels.
allowMaximize A Boolean value that specifies whether the dialog can be maximized. True if the Maximize button is shown; otherwise, false.
showMaximized A Boolean value that specifies whether the dialog opens in a maximized state. 1. True the dialog opens maximized. 2. Otherwise, the dialog is opened at the requested size if specified; or 3. the default size, if specified; or 4. the autosized size.
showClose A Boolean value that specifies whether the Close button appears on the dialog.
autoSize A Boolean value that specifies whether the dialog platform handles dialog sizing.
dialogReturnValueCallback A function pointer that specifies the return callback function. The function takes two parameters, a dialogResult of type SP.UI.DialogResult Enumeration and a returnValue of type object that contains any data returned by the dialog.
args An object that contains data that are passed to the dialog.

Okay - how to use this new knowledge in practice? See below for an example!

Example of a SharePoint pop-up with custom options

If you decide to open the pop-up with options, your code might look something like this:

var options = SP.UI.$create_DialogOptions();
 
options.title = "A standard SharePoint Publishing site in a dialog will look funky.";
options.width = 400;
options.height = 600;
options.url = "https://yourtenant.sharepoint.com/sites/publishing";

// Note the different casing here:
SP.UI.ModalDialog.showModalDialog(options);

Simple and straightforward!

See these 2 MSDN articles for more info:

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Craig
2019-06-07 11:48:10)
Any idea how we could accomplish the same in a modern site?
2019-06-08 00:15:52
Hi Craig! Thanks for your comment. To the question: yes - but with Modern, the right approach depends on what you're trying to do. One example of creating dialog windows in Modern SharePoint is this SPFx sample: react-command-dialog. Not exactly the same functionality, but probably the closest there is right now.
rohit aggarwal
2019-11-28 10:22:55)
thanks for the information
David
2019-12-24 05:14:39)
Hello, I've got the gist of the pop up dialog method and was able to implement it sucessfully for a custom "New Item" button to an InfoPath form. My question is, is there a way to get an "Edit Item" button based on the selection of an item the user clicks (i.e. the checkbox of an item) in a list web part for example. Scenario: User create a new item using custom "new Item" using the dialog box method. User goes back and wants to edit the item but is told to use the custom "edit" button. They click the checkbox in the list web part, and go to the custom "edit item". I guess I'm trying to figure out how to grab the value/ID of the item in the list web part and having it passed to the edit button. Thanks, David
2019-12-31 21:38:23
Hi David, Thanks for your question! I suppose that depends on the implementation of the checkboxes (or other "list view") by which you show the different items the users could edit! It needs to either contain the Id of the list item, or you need to build the logic to retrieve it programmatically. After that, you can always show the EditForm with the Id parameter as long as you get the Id from somewhere, and just add IsDlg=1 to get the popup to look nice. Hope that helps! Happy 2020!
Theresa
2020-07-23 15:43:46)
Hi there, do you have an idea how only to pop up a comment box when moving the mouse over or clicking on a specific word of the SharePoint page? Thanks in advance Theresa
Antti K. Koskela
2020-07-29 23:20:21
Hi Theresa, Thanks for your question! The right implementation would depend on whether you're on Modern or Classic, and whether you need it to be customizable without deploying new code or not?
Lisa
2020-10-06 09:56:32)
Hi there, Thanks for the info, and this may be silly question - but where do I insert the code on the SharePoint site? I am a complete newbie to this. Thanks!
2020-10-10 21:46:58
Hi Lisa! Since this guide was written for Classic SharePoint, you could use a script editor webpart (probably the easiest option of available!), custom action (also called a script link) or edit a page layout directly. Hope that clarifies the case, and if it doesn't, be sure to let me know! 😊
ROlla
2020-12-09 23:27:15)
Hello, Thanks alot for the amazing info.. I want to use the pop up with options.. but how to link it with <a> tag?
ROlla
2020-12-09 23:47:12)
THanks I used it now.. but the pop up in my long page shows on top of the page.. how to solve that please?
Antti K. Koskela
2020-12-12 22:06:18
Hi ROlla, Thanks for your comments! It's been a while since I've been doing much with Classic, but at least the Modal dialog should always be shown in the center of the current view. If you're using IE and it's messing up (I reckon it's the only browser that messes up the positioning, as well as most other things...) you could try modifying the positioning rules - with jQuery, it'll be something like this: if (jQuery(window).scrollTop() > 0)  jQuery('.ms-dlgContent').css('top', jQuery(window).scrollTop() + (jQuery(window).height() - jQuery('.ms-dlgContent').height()) / 2 + "px");
APPS 365
2022-07-06 22:32:34)
[spammy ad removed]
Antti K. Koskela
2022-07-28 15:03:25
Sup Sumeet (I'm guessing that's you anyway, please feel free to properly introduce yourself if not), Please don't spam my articles. It's a pretty bad marketing strategy, and will mostly serve to create bad blood between you and the community. Thanks!
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-19T18:57:41Z