I will need to pop up a new window on page load in SharePoint 2010 and SharePoint 2013 pages.

I embedded the following code using the CEWP or Script Editor web part, but it doesn't work for me.

Can you please let me know how I should modify the code? Thanks

OnLoad="DesignerWizWin=window.open('http://www.designerwiz.com', `'DesignerWizWin', 'toolbar=0, location=0, directories=0, menuBar=0, scrollbars=1, resizable=1, width=500, height=400, left=50, top=50');"`
  • Using DesignerWizWin the code would need to be inside body-element. Instead go with a simple JavaScript as W3 guides. – moe Jul 21 '17 at 7:21
  • Thanks for your answer ... I don't know how to add the code between the <body> tag in SharePoint 2013 pages, can you please give me a clue? – T Zhang Jul 21 '17 at 7:28

I think that the right approach would be to use the ModalWindowDialog from Sharepoint. To do this, add a scriptEditor webpart and add this:

function displayProfileLayover(url,windowTitle) {
      var options = SP.UI.$create_DialogOptions();


        if (windowTitle) options.title=windowTitle;
        else options.title="";    //no popup window title


Then, you could use that function to open a popup after page is fully loaded, doing somethink like this:

window.onload=displayProfileLayover('http://www.designerwiz.com', `'DesignerWizWin');

Or create the window only after the page load has been completed:

document.addEventListener("DOMContentLoaded", myCustomFunc);  //Execute only after page is fully loaded
     myCustomFunc(){ displayProfileLayover('http://www.designerwiz.com', `'DesignerWizWin'); }

You can search for all the options that this module offers over here "sharepoint modal dialog

  • 1
    Quick question @Alberto, where would I have to add either of the two code snippets that calls the displayProfileLayover function? I couldn't get it to work thus far. Thanks. – colonel_claypoo Aug 31 '18 at 7:31
  • Hi! I just realized of some error in my description. Please read it again, it should work now :) – Alberto Aug 31 '18 at 8:15
  • Thanks for updating but I still can't get it to work. Doesn't it work in SharePoint Online? What I did was insert a content editor webpart referencing a .js file that I uploaded to /SiteAssets. This .js file contains your code in the order your posted it minus the window.onload=displayProfileLayover('designerwiz.com', `'DesignerWizWin'); part. – colonel_claypoo Aug 31 '18 at 8:56
  • 1
    This is intended for sharepoint on premises. In spOnline it maybe another Js method. Add also the 'http(s)://' string. Window.onload maybe occur before the requires SP js file has been loaded. Use the eventListener described in my example. – Alberto Aug 31 '18 at 9:29

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.