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
Pavan KembaPavan Kemba 

onClick Javascript

I have a custom button and have implemented onClick Javascript as below
var url = '{!myvar}'
if (url != '') {
if({CONTAINS(url,"+")}){
{SUBSTITUTE(url, "+","%2B") }
}
  window.open(url);
} else {
  alert('Report URL was not found.');
}

But on click of the button i get the follow error
A problem with the OnClick JavaScript for this button or link was encountered:

Unexpected string literal "+". Expected a parameter pattern or a ')' in parameter list.

Please help me fixing this.
Pavan KembaPavan Kemba
My requirement is to replace all "+" in url to "%2B"
Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
 
var url = '{!myvar}'
if (url != '') {
if(url.includes("+")){
    url=url.replace("+","%2B");
}
  window.open(url);
} else {
  alert('Report URL was not found.');
}

Let us know if it helps