[SalesForce] Passing Id value from a parent page to popup on button click

I have a requirement of passing the Id of the parent page to the pop-up form, so that when a user clicks the 'CANCEL' button on the pop-up the control gets transferred back to the parent page.

For this, I need to have the Id of the original page in context. This page has a custom button which when clicked opens up a pop-up.

Any help is appreciated.

Here is the code that opens up a pop-up…

{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
{!REQUIRESCRIPT('/js/functions.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/jquery-1.8.2.min.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/ui/jquery-ui-1.9.1.custom.min.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/postmessage/jquery.ba-postmessage.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/bbq/jquery.ba-bbq.min.js')} 
requireCssFile('/resource/jQueryForPopup/jQuery/ui/css/ui-lightness/jquery-ui-1.9.1.custom.min.css'); 


function requireCssFile(filename) 
{ 
var fileref = document.createElement('link'); 
fileref.setAttribute('rel', 'stylesheet'); 
fileref.setAttribute('type', 'text/css'); 
fileref.setAttribute('href', filename); 
document.getElementsByTagName('head')[0].appendChild(fileref); 
} 


var j$ = jQuery.noConflict(); 
var iframe_url = '{!URLFOR("/apex/Add_address")}'; 

var j$modalDialog = j$('<div id="opppopup"></div>') 
.html('<iframe id="iframeContentId" src="' + iframe_url + '" frameborder="0" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no" />') 
.dialog({ 
autoOpen: false, 
title: 'Add Details', 
resizable: true, 
width: 800, 
height: 540, 
autoResize: true, 
modal: true, 
draggable: true 
}); 

j$modalDialog.dialog('open');

Here is the VF page:

    <apex:outputPanel id="tstpopup">

         <apex:pageBlockSection >
         <apex:pageblockSectionItem >
            <apex:outputlabel for="Address_Line1">
            Address Line 1
            </apex:outputlabel>
            <apex:panelGroup >

            <apex:inputtext id="Address_Line1" value="{!AddrLine1}" required="true"/>


                            <apex:pageBlockSection >
         <apex:pageblockSectionItem >
            <apex:outputlabel for="Country">
            Country
            </apex:outputlabel>
            <apex:panelGroup >

            <apex:inputText id="Country" value="{!Country}" required="true"/>

            </apex:panelGroup>
            </apex:pageblockSectionItem>
            </apex:pageBlockSection>


            <apex:commandButton value="Cancel" action="{!closePopup}" onclick="window.close();">

            </apex:commandButton>
            <apex:commandButton value="Save" action="{!save}" rerender="abcd">

            </apex:commandButton>

  </apex:outputPanel>

The user after entering Address Line 1 and the country fields can either click CANCEL or SAVE buttons.

Best Answer

You can pass values by using the query string.

var iframe_url = '{!URLFOR(/apex/Add_address?parent_id=your_parent_page_id)}'; 

And then in the popup page controller constructor, grab the id like below

String ppId = System.currentPageReference().getParameters().get('parent_id');