I am looking for a solution where when I click on a button, the resulting page should open in the same window below the button. Below is my current VF page, right now the page is opening in a new tab.

<apex:page lightningStylesheets="true">
    body input.btn, body input.btnDisabled, body input.btnCancel {
    padding: 4px 3px;
    padding-left: 1rem;
    padding-right: 1rem;
    text-align: center;
    vertical-align: middle;
    justify-content: center;
    border: 1px solid #dddbda;
    transition: border .15s linear;
    background-color: #0070d2;
    border-color: #0070d2;
    /* color: #fff; */
    width: 300px;
    height: 35px;

<apex:form target="_self" >

            <apex:commandButton id="one" value="Lead Page" oncomplete="openDashboard(this.id);" />&nbsp;&nbsp;
            <apex:commandButton id="two" value="Account Page" oncomplete="openDashboard(this.id);"/> 

<script type="text/javascript">
function openDashboard(clicked_id) {
        window.open("Lead URL");
    }else if(clicked_id.includes('two')){
        window.open("Account URL");

2 Answers 2


In order to ensure that the link is opened in the same tab, you should use


See the example below:


Source - http://www.w3schools.com/jsref/met_loc_replace.asp


You can use below syntax to open the url in the same page.


Check the window.open method and its parameters at https://www.w3schools.com/jsref/met_win_open.asp

Another solution would be to use replace as suggested by Sahil (upvoted). I cannot think of cons and pros of any approach so its upto you how you would like to go.

You must log in to answer this question.

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