Using CommonShowModalDialog in SharePoint

I’ve not found any post explaining the usage of CommonShowModalDialog in SharePoint, the default popup used by SharePoint across the board. So I thought why can’t I make one.

The method exists in core.js and it is used OOTB by SharePoint for opening popups in places like selecting a web application from a list of web applications, selecting a site collection from a list of site collections etc. (you could see these in Central administration). So here is the method –

function openPopup(){
    commonShowModalDialog("/_layouts/selectitem.aspx", "resizable: no; status:no; scroll: no; help: no; center: yes; dialogwidth:410px; dialogHeight:300px;", RetrieveItemValue);

CommonShowModalDialog has similar parameters as a simple

  1. Target URL
  2. Window features
  3. Callback function

To pass a value from the popup to the parent page use window.returnValue in te popup to save the value before closing the window.

//called from the popup page
function closePoup(){
    window.returnValue = myValue;

Retrieve the value passed from the popup in the callback function mentioned.

//Retreives the value sent from the popup
function RetrieveItemValue(retValue) {

As simple as that.