How can I create a clickable link?

I am making the link generator right now. First of all, I am creating the link then I send the link to my friend but he can’t click the link because of empty characters and another thing. But if you copy the whole of the message string that I send you and paste the address bar in the browser you can reach the link. Because the browser can handle the space and empty characters. I am trying to find a solution I have to make this manipulation before that browser thus my friend can easily click the link and go to the page. Otherwise, I said before he needs to copy whole the link and paste it to the browser I don’t wanna happen.

this is the link that I send to my friend (FOCUS THE LAST WORD)

https://github.com/nodesource/distributions/blob/master/README.md#user-content-installation-instructions:~:text=Node.js%20v14.x%3A#:~:text=Node.js v14.x:

but I want to transform this to this

https://github.com/nodesource/distributions/blob/master/README.md#user-content-installation-instructions:~:text=Node.js%20v14.x%3A#:~:text=Node.js%20v14.x:

Answer

You can so something like this:

function link(str) {
  return str.split(" ").join("%20");
}

This will replace all empty spaces with %20 and return the modified link.


Check it in action below:

function link(str) {
  return str.split(" ").join("%20");
}

console.log(link("https://github.com/nodesource/distributions/blob/master/README.md#user-content-installation-instructions:~:text=Node.js%20v14.x%3A#:~:text=Node.js v14.x:"));

Leave a Reply

Your email address will not be published. Required fields are marked *