function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Arup SarkarArup Sarkar 

Opening a popup window in visualforce

Hi:

 

I am using the following in my visualforce page to open a new window but it is opening in the same window, can anyone please tell me how to open a popup window ?

 

    <script type="text/javascript">
    function popupwindow(){
        var newwindow = window.open('/apex/CallReportDataComponentPage','Call Report'); 
        newwindow.focus();
    }
    </script>

<apex:commandButton action="{!InvokeCallReport}" value="Generate Report" onclick="popupwindow"/>

 

DannyK89DannyK89

I have always used this when I wanted to have a pop up window:

 

window.open('URL',
'Popup','height=400,width=1000,left=100,top=100,scrollbars=yes,toolbar=no,status=no');

 

I put it in the onclick="" .

bob_buzzardbob_buzzard

Given that you are using a commandbutton, you may also want to return false from the onclick handler, otherwise the form submission will continue.

Arup SarkarArup Sarkar

Thanks everyone for replying, it is still not working it is still opening in the same window. I will depict the sequence of action followed.

 

step 1:

 

User enters parameters in "CallReportsSummaryPage", which has button, which is eventually mapped to a Apex Class. below is my modified code of the VF page.

 

    <script type="text/javascript">
        function popupwindow(sCallReportIdParam)
        {
            var newwindow = window.open('/apex/CallReportDataComponentPage?id='+sCallReportId, 'Call Report',scrollbars=yes,toolbar=no,status=no);
            newwindow.focus();

        }
    </script>

<apex:commandButton action="{!InvokeCallReport}" value="Generate Report" onclick="popupwindow(sCallReportId)"/>

 

step 2: 

The InvokeCallReport() PageReference function gets invoked in the Apex class, please see the code below.

    public PageReference InvokeCallReport()
{
    sCallReportId = ReportParams.Id;

        PageReference p = new PageReference('/apex/CallReportDataComponentPage' + '?id=' + sCallReportId);
        p.setredirect(true);
        return p;

}

 

step 3:

 

CallReportDataComponentPage is mapped to getCallReportData() in the apex class, see code below.

public List<Task> getCallReportData(){
{

   List<Task> CallReportData = [some SOQL];
   return CallReportData;
}

 

 

 

Arup SarkarArup Sarkar

Clarification:

 

In my popupwindow function I do have sCallReportIdParam in my window.open function.

Pradeep_NavatarPradeep_Navatar

You can use target="_parent" property to open a pop up window in a parent window. Try out       window.open(url,target="_parent");

hemantgarghemantgarg

try the target _blank like following :-

var newwindow = window.open('/apex/CallReportDataComponentPage','Call Report' '_blank'); 
bob_buzzardbob_buzzard

If you want some sample code, here's a blog post that mimics a Salesforce lookup in Visualforce, including opening a popup window:

 

http://bobbuzzard.blogspot.com/2010/09/visualforce-lookup.html

 

SaktiSakti
Hi Arup,

Hope this will help you opeing popup in new window.

<script type="text/javascript">
    
    function OpenPreviewPopUp()
    {
        var w = window.open('/apex/CallReportDataComponentPage',"MsgWindow", target='_blank')
        return w;      
    }  
    </script>

Thanks,
SAKTI