I’m using the extension "Custom right-click menu" to add a custom site search. When I use the context menu, it adds spaces to the search term. I need it to have a +.
var search = crmAPI.getSelection() || prompt('Please enter a search query');
var url = 'https://www.subetalodge.us/list_all/search/%s/mode/name';
var toOpen = url.replace(/%s/g,search);
window.open(toOpen, '_blank');
2
Answers
This correction should work:
Whole code:
To replace spaces with a
+
sign in the search term before constructing the URL, you can modify your code slightly to use theencodeURIComponent()
function. This function will encode spaces as%20
, which is equivalent to a+
sign in URL encoding. Here’s how you can update your code: