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
SFDC developer55SFDC developer55 

onclick javascript from visual force

On click of command button (from Inline visual force page), I need to open different window for partners or append partners in a URL, when button is clicked from partners community otherwise the regular URL.

Command button is like this:

<apex:commandButton id="btn" value="Add product" onclick="window.open('/{!IF(boolPartner,$Label.AddOpptyProductPartnerURL,$Label.AddOpptyProductURL)}={!opportunity.name}&retURL=%2Fa0a%2Fo','_blank','height=400,location=no,resizable=yes,to


Any idea how we can do this on click..

I have tried to write a code on controller but that method was not called:


public Controller(ApexPages.StandardController cont) {

    String hostVal  = ApexPages.currentPage().getHeaders().get('Host');
    String urlVal = Apexpages.currentPage().getUrl();
    String URLL = 'https://' + hostVal+ urlVal;
    Boolean result=URLL.contains('partners');
    system.debug(URLL+'==URLL=='+result);
    return result;
  }
bob_buzzardbob_buzzard
You have to do this client side - you can't open a new window from the controller.

What is going wrong with your onclick handler?  When you look at the page source does the URL look valid?

One thing - you'll want to return false after your window.open function call, otherwise the form will be submitted.