Can anyone tell me how to redirect one visualforce page to another visualforce page automatically ?
below is my visualforce page :

< apex:page standardController="Account"
contentType="application/msWord/#Test-{!NOW()}.doc" recordSetVar="accounts" sidebar="false" cache="true">

<html xmlns:w="urn:schemas-microsoft-com:office:word">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

        <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 headerValue="Account Number">
                             <apex:outputText >{!ac.AccountNumber}</apex:outputText>
                         <apex:column headerValue="AccountType">
                             <apex:outputText >{!ac.Type}</apex:outputText>
                         <apex:column headerValue="Phone Number">
                             <apex:outputText >{!ac.Phone}</apex:outputText>

           <apex:outputText value="hi dude,"/>


        function redirect(){

        window.onload = window.setTimeout(redirect(),5000);


My question is once the document is downloaded then it will automatically redirect to another page as mentioned above.
I have tried using action attribute,calling redirect method from constructor. but nothing happen.
Finally I got the idea is using javascript we can redirect automatically. but it dosent work for me.

Someone please tell me what I have to modify.

Thanks in advance

2 Answers 2


Try using code given below in your first page :

PageReference OpenNewPage = Page.yoursecondpage;
return OpenNewPage;

So that it won't redirect but download the word file. Let me know if this works for you.


Try using following code :

     <apex:commandButton value="openWindow"   onclick="window.open('https://c.ap1.visual.force.com/apex/AccountasTextfile');"/>
  • it doesn't work for me Commented Apr 3, 2015 at 10:13
  • Actually my problem is: I have two vfp. First page contain download button. If I click that button then it will redirect to this page and download the content as word document.Once the doc is downloaded then it will automatically redirect to first page Commented Apr 3, 2015 at 10:14
  • For that What I have to do Commented Apr 3, 2015 at 10:15
  • So now your 2nd page doesn't redirect you to first page? Is it the problem?
    – Poonam
    Commented Apr 3, 2015 at 10:17
  • Yeah. I don't know why it doesnt redirect automatically Commented Apr 3, 2015 at 10:29

You must log in to answer this question.

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