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
Raksha NarayanRaksha Narayan 

Changing the VF Page name in the URL on click of javascript button.

Hi, I have a javascript button on which i am calling a VF page. The name of the VF page is 'MyPage'. However, on the click of the javascript button, i want the VF page in the URL be displayed as "MyFirstVFPage".
Can anyone help me on this, please?
pradeep kumar yadavpradeep kumar yadav
<a href="" id="ancherId" target="_blank"></a>
        <script type="text/javascript">
    function ABC() {
                        document.getElementById("ancherId").setAttribute('target', '_self');
                        document.getElementById("ancherId").href = '/apex/VFpageName';
If you want to navigate to another page on button click then you can call the javascript function on "onClick" button event.

or if you only want to change the name in URL then use this code on "onClick" button event:- 
function changeURL() {
            var url = window.location.href;
            url = url.replace('firstPageName','SecondPageName');
            window.history.replaceState({}, document.title, url);

 Note:- If you got solution marked it as best answer to help others find their solution easily.