+ Start a Discussion
Abhish ChalkeAbhish Chalke 

window.open not working in VF page

<button class="btn-view-all" onclick="openall()">View All   </button>

JS function
function openannouncement(){
            var urlString=window.location.href;
            var baseURL = urlString.substring(0, urlString.indexOf("/_ui"));
            var siteBaseURL = baseURL + '/s';
            var redirectUrl = siteBaseURL + '/viewall'
            window.open(redirectUrl,"_self");
         }

after clickig on view all button
browser URL is changing as expected but page is not redirecting 
AbhishekAbhishek (Salesforce Developers) 
https://salesforce.stackexchange.com/questions/218725/window-open-is-it-works-in-lightning-experience-or-not

https://trailblazers.salesforce.com/answers?id=9063A000000l10fQAA

https://developer.salesforce.com/forums/?id=9060G000000I6psQAC


Your query is answered above.

Try the suggestions mentioned above.
Ashish Kumar YadavAshish Kumar Yadav
Hi Abhish Chalke,

try below code it is working my vf page .
   <script>
        function openschemedetails() {
            var id = "{!sam.Scheme_Master__c}";
            var url = 'apex/scheme_detail?id='+id;
            
            window.open('https://wel--wpc--c.visualforce.com/'+url,'_blank');
        }
        </script>

<apex:commandButton styleClass="slds-button slds-button_brand" value="View Details"  onclick="openschemedetails(); return false;"/>

if you face any problem please let me know.

if it is work for you please mark as the best answer.
Malika Pathak 9Malika Pathak 9
Hii Abhish Chalke

In your above code, your function in onclick should have the same function in JS.


Below I have put a solution for your code.

<button class="btn-view-all" onclick="openall()">View All   </button>

JS function

function openall(){
            var urlString=window.location.href;
            var baseURL = urlString.substring(0, urlString.indexOf("/_ui"));
            var siteBaseURL = baseURL + '/s';
            var redirectUrl = siteBaseURL + '/viewall'
            window.open(redirectUrl,"_self");
         }

Please go through the above code, Reply if you have any doubt, and Mark it as Best Answer if it is helpful to you.

Thanks and Regards,
Malika Pathak.