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
rosscorossco 

Alert on VF Page - then redirect?

Hi

 

I am calling a VF page from a Custom Button. I have successfully managed to display an alert to the user if certain conditions are met. How can I redirect the user to the original page that had the custom button after this message is displayed? I am displaying the message using the following:-

 

 <script language = "JavaScript">
   var msg = 'There is no valid Contact Record or Contact Role - You may not send an Email until this is done.'
   if ('{!validtoflag}' == 0) {
   	alert (msg);
   }
 </script>

 

 Many thanks

Ross

 

Navatar_DbSupNavatar_DbSup

Hi,

 

You can open the vf page as a child window. After displaying the alert you can close the childe window and reload your parent window where you have your custom button.

 

Try the below code snippet as reference:

 

<apex:page >

<script>

function closeme1()

{

alert('ppp');

window.parent.opener.location.reload(true);

window.parent.close();

}

</script>

<apex:form >

  <apex:commandButton value="close me and referesh" onclick="closeme1()"/>

 </apex:form>

 

</apex:page>

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

 

 

bvramkumarbvramkumar

You are having a custom button on an object's layout which means for e.g. If your page is "Testpage" and on Custom button you have defined like to redirect the user to "/apex/TestPage?Id={!Account.Id} ", it will automatically pass the account Id to your VF page... So in the javascript you need do the below.

 

<script>

// put the below stmt. after your validation and the alert message. 

 window.open('../' + '{!$CurrentPage.Parameters.Id}');

</script> 

Mouse.liuMouse.liu

when you click the custom button, you can set the retURL parameter, after redirecting to visualforce page, you can use it in javascript code by assign the retURL to an page context variable.

nagalakshminagalakshmi

Hi Rossco,

 

Try this code

 

<apex:page controller="GeneratePPI" action="{!insert1}" showHeader="false" sidebar="false">
<apex:form >
<apex:outputPanel rendered="{!errormsg}">
   <script type="text/javascript">
    {
     window.parent.location.href ="/{!$CurrentPage.parameters.id}";
    window.alert("This Puchase Order is Already inserted in PPI "); }
    </script>
  </apex:outputPanel>
</apex:form>
</apex:page>


errormsg is boolean type declare this class. True this boolean type in your method and declare this as false in constructor.

 

Thanks,

Lakshmi