[SalesForce] How do we create a popup from VF page

I have a VF page with couple of buttons. I need to show a popup when one of the buttons is clicked. Something like a modal popup where user has to fill in something or click the cancel button in the popup page before to go back to the calling page.



Lets assume i would need to have lookup for contact in VF page and if the contact is not there then we need to create a new contact record. So i am kind of trying to create a contact record from the same page by just clicking a button which in turn displays the fields of contact and save of it creates the contact record.So the user doesnt need to go away from this page to create the new contact record.

Best Answer

weve used this before: http://www.tehnrd.com/visualforce-pop-up/ but that aside.

If you are using a lookup window to find a contact, what about creating a custom lookup window to which you add a "create contact" button. Use the create button to replace the lookup content with new contact fields right in that window, simple as re-rendering the page using render flags. That way its in keeping with standard salesforce UX and your users will possibly embrace the custom functionality more easily.

The only moderately difficult part is getting the selection back from the child lookup window to the parent.

These functions go on the parent VF page:

function openPopupFocus(a, b, c, d, e, f, g, k) {

    if (f) {
        if (lastMouseX - c < 0) 
            lastMouseX = c;
        if (lastMouseY + d > screen.height) 
            lastMouseY -= lastMouseY + d + 50 - screen.height;
        lastMouseX -= c;
        lastMouseY += 10;
        e += ",screenX=" + lastMouseX + ",left=" + lastMouseX + ",screenY=" + lastMouseY + ",top=" + lastMouseY

    curPopupWindow = window.open(a, b, e, false);

    if (k) 
        closeOnParentUnloadWindow = win

function closePopup() {
    if (closetimer) {
        closetimer = null
    if (curPopupWindow != null) {
        try {
            if (curPopupWindow.confirmOnClose) if (curPopupWindow.confirm(curPopupWindow.confirmOnCloseLabel)) {
                curPopupWindow.confirmOnClose = false;
                return false
        } catch (a) {}
        curPopupWindow = null

function doLookupPick(a,b,c,d){

the link to open the window

  openPopupFocus(%27/apex/<VF PAGE NAME>?filter=item%27, %27CCBCCLookup%27, 420, 490, %27width=420,height=490,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no%27, true);

This function goes on the custom lookup page:

function sendToParent(selectedId,selectedName){

        top.window.opener.doLookupPick(<hidden field dom id>,
                                         <selected sfObject ID>,
                                         <text input field dom id>',
                                         <text input contact name>);