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
Karthick RajaKarthick Raja 

Redirect to Home Page once the word doc is downloaded

Hi folks,
   Can anyone tell me how to redirect the homepage from download page automatically ?
I have a visualforce page which downloads the content of the page.Once the document is downloaded then it will automatically redirect to home page.
For that How can I implement.

My vfp
 
<apex:page standardController="Account" extensions="AccountDownload" contentType="application/msWord/#Test-{!NOW()}.doc"  recordSetVar="accounts" sidebar="false"  cache="true"> 
    <apex:form >
        <apex:pageBlock title="Archiver For Account">
        <apex:pageBlockSection >
               <apex:pageBlockTable value="{!accounts}" var="ac" >
                     <apex:column headerValue="AccountName">
                         <apex:outputText >{!ac.Name}</apex:outputText>
                     </apex:column>
                     <apex:column headerValue="Account Number">
                         <apex:outputText >{!ac.AccountNumber}</apex:outputText>
                     </apex:column>
                     <apex:column headerValue="AccountType">
                         <apex:outputText >{!ac.Type}</apex:outputText>
                     </apex:column>
                     <apex:column headerValue="Phone Number">
                         <apex:outputText >{!ac.Phone}</apex:outputText>
                     </apex:column>
                                       
                 </apex:pageBlockTable> 
            </apex:pageBlockSection>
        </apex:pageBlock>
    
   <apex:outputText value="hi dude,"/>
   </apex:form>
</apex:page>

Controller:
  
public class AccountDownload {    
    public boolean ren{get;set;}
    public AccountDownload(ApexPages.StandardSetController controller) {
        ren=false;
        rtnToHome();
        
    }
    public PageReference Download(){
        ren=true;
        return null;
        
    }
    public PageReference rtnToHome(){
        PageReference demoPage = new pagereference('/apex/AccountasTextfile');
        demoPage.setRedirect(true);
        return demoPage;
    }
}

I have tried action attribute on page tag but nothing happne.
Please let me know is there any way to automatically redirect after the document is downloaded


Thanks in advance
Karthick
Sagar PareekSagar Pareek
 I've handled this in the past is to embed the TEXT File download Visualforce page as an iframe in a wrapper Visualforce page. The wrapper can provide a button or link for the user to return to the previous page, or set a javascript timeout that goes back to the original page after a certain amount of time. I usually favour the former, as if the user is slow to accept the download they may be surprised to be taken elsewhere.
AnjaneyluAnjaneylu
Hi Karthick,
i have on doubt..
what is the purpose of  public boolean ren{get;set;}.
this is normally property of {! }.
but this was not defined in the VF.
and download() and rtnHome() methods were  also not defined in VF but you have used..
how it is possible?
please kindly explain me..
Thanking you in advance..
 
Karthick RajaKarthick Raja
@Anji:

My first vfp code is:
 
<apex:page standardController="Account" extensions="AccountDownload" recordSetVar="accounts" sidebar="false">
    <apex:form >
        <apex:pageBlock title="Archiver For Account">
        <apex:pageBlockSection >            
            <apex:commandButton action="{!Download}" value="download" id="theButton"  /><br/>
             
        </apex:pageBlockSection>
        </apex:pageBlock>        
    </apex:form>  
</apex:page>

2nd page is:
<apex:page standardController="Account" extensions="AccountDownload" contentType="application/msWord/#Test-{!NOW()}.doc"  recordSetVar="accounts" cache="true" sidebar="false"  > 
    <html xmlns:w="urn:schemas-microsoft-com:office:word">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <body>                       
            <apex:form >
                <apex:pageBlock title="Archiver For Account">
                     <div style="text-align:left" >          
                         <apex:pageBlockTable value="{!accounts}" var="ac" >
                             <apex:column headerValue="AccountName">
                                 <apex:outputText >{!ac.Name}</apex:outputText>
                             </apex:column>
                             <apex:column headerValue="Account Number">
                                 <apex:outputText >{!ac.AccountNumber}</apex:outputText>
                             </apex:column>
                             <apex:column headerValue="AccountType">
                                 <apex:outputText >{!ac.Type}</apex:outputText>
                             </apex:column>
                             <apex:column headerValue="Phone Number">
                                 <apex:outputText >{!ac.Phone}</apex:outputText>
                             </apex:column>                                       
                         </apex:pageBlockTable>  
                      </div>           
                    </apex:pageBlock>
    
               <apex:outputText value="hi dude,"/>
           </apex:form>
        </body>
    </html>
</apex:page>

Extention for both pages as follows:
public class AccountDownload {    
    
    public AccountDownload(ApexPages.StandardSetController controller) {
       
        rtnToHome();
        
    }
    public PageReference Download(){
        ren=true;
        PageReference demoPage = new pagereference('/apex/DownloadTextfile');
        demoPage.setRedirect(true);
        return demoPage;
        
        
    }
    public PageReference rtnToHome(){
        PageReference demoPage = new pagereference('/apex/AccountasTextfile');
        demoPage.setRedirect(true);
        return demoPage;
    }
}

My question is: when I click download button on first page then the content of the second page will download .
Once download is complete then automatically redirect to my first page.
For that What I have to modify.

Please help on this