0

i want to open new page as new window... in the beginning i used apex:CommandLink and target="_blank" and it worked well.

But i want to add validation in java-script so i used in Apex:ActionFunction So i want to know how can i open new page from action function in new Window .

I appreciate if you can answer...

Javascript:

   function PdfReport(id)
         {
         var selectCheckbox = false;
         var tab =  document.getElementById(id).getElementsByTagName("table")[0];
               for(j = 0 ; j < tab.rows.length ; j++) 
                { 
                   if (tab.rows[j].cells[0].querySelector("input[type='checkbox']").checked == true )
                   { 
                        selectCheckbox = true;  
                   }  
                }
        if(selectCheckbox  == false)
           {
                alert('You must select at least one technology in order to export ');
                return;
            }
         exportPdf();   
         }

Apex page:

<apex:actionFunction action="{!Export}" name="exportPdf" />

<apex:commandLink rendered="{!visible}" styleClass="exportTo" value="export result to Pdf" id="exportPdf"  target="_blank"
  onclick="PdfReport('mainPage:mainForm:pageBlock:sectionSearch:searcResult_:result:blockdetail'); return false"/> 
5
  • 1
    Have you tried window.open?
    – Keith C
    Commented Dec 8, 2014 at 13:19
  • no cause i am open the new page from the controller
    – Racheli
    Commented Dec 8, 2014 at 13:37
  • 3
    A server can't tell a browser to open a new window or tab; the action has to be initiated from the browser-side e.g. straight after PdfReport calls exportPdf.
    – Keith C
    Commented Dec 8, 2014 at 15:06
  • actionFunction could also do URLFOR to a VF page that displayed the PDF
    – cropredy
    Commented Dec 8, 2014 at 17:38
  • That right thanks a lot for your comment its help me a lot ....
    – Racheli
    Commented Dec 9, 2014 at 7:49

1 Answer 1

1

OK So after research i cant redirect new page in new window from server side , so used in other method : first of all i make validation in java script and if it return true the action in the controller running ,

JavaScript

 function PdfReport(id,type)
         {
         var selectCheckbox = false;
         var tab =  document.getElementById(id).getElementsByTagName("table")[0];
               for(j = 0 ; j < tab.rows.length ; j++) 
                { 
                   if (tab.rows[j].cells[0].querySelector("input[type='checkbox']").checked == true )
                   { 
                        selectCheckbox = true;  
                   }  
                }
        if(selectCheckbox  == false)
           {
                alert('You must select at least one technology in order to export ');
                return false;
            } 
            return true;
         }

Apex:

   <apex:commandLink rendered="{!visible}" styleClass="exportTo" value="export result to Pdf" id="exportPdf"  target="_blank"  action="{!Export}" onclick="return PdfReport('mainPage:mainForm:pageBlock:sectionSearch:searcResult_:result:blockdetail','Simple');"  />

the idea from : How to add a confirm dialog to a command button?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .