I'm trying to set up a pop up window with a URL to a document each time my Sharepoint site is loaded.

I read that it can be done by adding a content editor web part with a following code to a page:

<script type="text/javascript" src="/_layouts/14/sp.ui.dialog.js">
var options = SP.UI.$create_DialogOptions();
options.title = "My Dialog Title";
options.width = 400;
options.height = 600;
options.url = "http://www.google.com";

But I'm getting nothing. Please help identify what am I doing wrong.

  • 1
    Try removing 14 from src attribute Mar 25, 2014 at 17:21
  • Didn't work. BTW, should sp.ui.dialog.js file be uploaded somewhere to sharepoint or can it be in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS ?
    – Taras
    Mar 25, 2014 at 17:30
  • It resides in layouts. Try using sp.sod.executefunc. I am on mobile and can't give you full details. Search for sp.sod.executefunc or executeordelayuntilscriptloaded Mar 25, 2014 at 17:41
  • Nadeem Yousuf, thanks for a suggestion, I'll try that and report a result.
    – Taras
    Mar 25, 2014 at 18:53
  • Nadeem,I tried using sp.sod.executefunc, got no errors and no warnings, but did't get a popup window I need.
    – Taras
    Mar 31, 2014 at 16:25

3 Answers 3


Short summary of what I did:

1- Added CEWP to my page and set Chrome type to none.

2- Added these refferences to a page itself:

<script src="/_layouts/sp.core.js" type="text/javascript"></script>
<script src="/_layouts/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/sp.js" type="text/javascript"></script>
<script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script>

3- Copied *.js files from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033 to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LAYOUTS

A code from CEWP:

<script type="text/javascript">
function popupwin(){ExecuteOrDelayUntilScriptLoaded(function ()
{var options = SP.UI.$create_DialogOptions();
options.title = "My Dialog Title";
options.width = 400;
options.height = 600;
options.url = "/Shared%20Documents/Forms/AllItems.aspx";

The issue is that you cannot put script tags into a CEWP.

In 2013 there is a Script Editor web part that works, but not in 2010.

The way to get around this issue is to load the script from a document.

Put the script into a .txt file (use notepad or something).

Upload it into one of the libraries on your site. It would be SharedDocuments or StyleLibrary.

Go into the web part settings of the CEWP and past the url of the file you just uploaded into the Content Link field.

Here is a tutorial.

  • I don't know why people never suggest using the HTML form web part. You can put scripts inside it without having to first create a separate file
    – MdMazzotti
    Mar 25, 2014 at 17:55
  • Hmm, interesting, never knew that existed. I guess I don't know enough about it to suggest it to anyone. Mar 25, 2014 at 18:07
  • Putting it in a separate file, and putting that file in Site assets and linking CEWP to that file didn't help.
    – Taras
    Mar 25, 2014 at 18:50
  • MdMazzotti, could you please specify how exactly can I do it with a HTML form web part, because I tried and seems like I'm doing something wrong again.
    – Taras
    Mar 25, 2014 at 18:52
  • Are you getting an error on the page? (hit f12 to see javascript errors). Try linking to something that is not google. I got this error Refused to display 'https://www.google.com/?IsDlg=1' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. Mar 25, 2014 at 18:56

Put this script in Content Editor Webpart:

<script type="text/javascript">
 //******** Basic Dialog Starts Here ***********/
 function openBasicDialog(tUrl, tTitle) {
     var options = {
         url: tUrl,
         title: tTitle,
         width: 1500,
        height: 1000
 //******** Basic Dialog Ends Here ***********/</script><a href="#" onclick="openBasicDialog('https://abc.com','Welcome Page');">ShowModal Dialog</a>


<a onclick='javascript:NewItem2(event, "http://www.google.com");javascript:return false;' 

href="https://www.google.com" target="_self">Show google In Modal Window</a>  
  • Thanks for your response, but that won't work in my case, because I need that window to popup automatically, not after hitting a link.
    – Taras
    Apr 17, 2014 at 19:08

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.