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"/> 
  • 1
    Have you tried window.open? – Keith C Dec 8 '14 at 13:19
  • no cause i am open the new page from the controller – Racheli Dec 8 '14 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 Dec 8 '14 at 15:06
  • actionFunction could also do URLFOR to a VF page that displayed the PDF – cropredy Dec 8 '14 at 17:38
  • That right thanks a lot for your comment its help me a lot .... – Racheli Dec 9 '14 at 7:49
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?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.