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
John Neilan 2John Neilan 2 

How to Refresh Current Window on Button Click?

I have the code below as a button in a VF page.  When clicked, a new tab opens up with the same page.  How can I prevent a new tab from being opened in the browser and just refresh the page where the user clicked the button?  I tried adding "_parent" and "_self" to the onclick code, but it didn't do anything.  Thanks.
 
<button
            class="btn" 
            style="background:#99C299; height:35px; width:250px;"
            onclick="javascript:window.open('/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}');">
            <b>Submit For Approval</b>
            </button>

 
Best Answer chosen by John Neilan 2
John Neilan 2John Neilan 2
FYI, I got this to work by switching to an <a> tag:
 
<a  role="button"
            class="btn" 
            style="text-decoration:none;background:#99C299; font-size:16pt; font-family:arial;padding-top:2px;padding-bottom:4px;padding-left:10px;padding-right:10px;border-radius:15px;height:35px;width:250px;"
            href = "/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}"
            target = "_self">
            <b>Submit For Approval</b>
        </a>

Thanks!

All Answers

Jai ChaturvediJai Chaturvedi
Hi,

Use this.

onclick="javascript:window.open('/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}', '_top');">

Mark solution if works.

Thanks
Jai
John Neilan 2John Neilan 2
Thanks.  However, that gives me the same behavior.  When I click the button, the page stays the same and does not refresh.
Jai ChaturvediJai Chaturvedi
Try this instead of window.open().


window.location.reload();
 
John Neilan 2John Neilan 2
Thanks, but that still gives me the same behavior.
Jai ChaturvediJai Chaturvedi
can you please paste the code.
John Neilan 2John Neilan 2
My buttob code is as follows:
 
<button
            class="btn" 
            style="background:#99C299; font-size:16pt; font-family:arial;padding-top:2px;padding-bottom:4px;padding-left:10px;padding-right:10px;border-radius:15px;height:35px;width:250px;"
            onclick="javascript:window.location.reload('/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}','_top');">
            <b>Submit For Approval</b>
            </button

 
Jai ChaturvediJai Chaturvedi
Just write 
window.location.reload();


Not javascript:window.location.reload('/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}','_top');
Dont give parameter value for this.
John Neilan 2John Neilan 2
Sorry, I misunderstoon.  Still not luck though.  Same behavior.
John Neilan 2John Neilan 2
FYI, I got this to work by switching to an <a> tag:
 
<a  role="button"
            class="btn" 
            style="text-decoration:none;background:#99C299; font-size:16pt; font-family:arial;padding-top:2px;padding-bottom:4px;padding-left:10px;padding-right:10px;border-radius:15px;height:35px;width:250px;"
            href = "/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}"
            target = "_self">
            <b>Submit For Approval</b>
        </a>

Thanks!
This was selected as the best answer