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
Kumar GKumar G 

how enable java script button code in Lightning

I have a below VF code for javascript button this is working in classic but in lightning it's not working , Please suggest me how to enable this code for Lightning.
 
<input type="button" value="New Program" class="btn" onClick="createNewProgram();" title="New Marketing Program record"/>

function createNewProgram() {
  window.open('{!URLFOR($Action.Marketing_Programs__c.New)}', '_new');
}

 
Wilfredo Morillo 20Wilfredo Morillo 20
You cannot use javascript buttons in lightning. 
Wilfredo Morillo 20Wilfredo Morillo 20
Maybe this could help you. 

https://developer.salesforce.com/blogs/developer-relations/2016/09/take-the-first-steps-ways-you-can-replace-javascript-buttons.html
Daniel Zeidler (DZ)Daniel Zeidler (DZ)
I think the problem could be that "window.open" is not supported in lightning experience.

The following code should work but may not open the the URL in a new window.
<input type="button" value="New Program" class="btn" onClick="createNewProgram();" title="New Marketing Program record"/>

function createNewProgram() {
  if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) {
    sforce.one.createRecord('Marketing_Programs__c');
  }
  else {
    // Set the window's URL using a Visualforce expression
      window.open('{!URLFOR($Action.Marketing_Programs__c.New)}', '_new');
  }
}
I recomend checking out the Visualforce & Lightning Experience Trailhead Module (https://trailhead.salesforce.com/modules/lex_dev_visualforce) for more information on what I changed here. More specifily the 5th unit: "Manage Navigation (https://trailhead.salesforce.com/modules/lex_dev_visualforce/units/lex_dev_visualforce_navigation)".

Another option you can try which should open the URL in a new window is just to use an archor element or similar visualforce component
<a href="{!URLFOR($Action.Marketing_Programs__c.New)}" class="btn" target="_blank" title="New Marketing Program record">New Program</a>
You may need to adjust some css to make the link look more like a button
 
Joseph AlstonJoseph Alston
Lightning doesn't support buttons built using JavaScript. coreball (https://coreball.co)