How to change part of string as url

Hi All

I am stuck with a scenario where I need guidance.

I have an attribute Message which contains a string "My name is Vivek https://www.google.com". I need to display this message attribute on my web page with url part as link on click of which it can open google web page . Please guide me over this. This should be implemented in both traditional web as well as mobile app.

Also let me know if any further details required.

Thanks in advance.

Solution

Hi Vivek Kumar,

You can use the below js in onready action

var string = "hei dude, check this link http:://google.com and http:://youtube.com"

var matches = string.match(/\bhttp?::\/\/\S+/gi);

document.getElementById($parameters.container).innerHTML ="<a href=https://www.google.com/> '"+matches+"'</a>";

console.log(matches);


Regards,

Ellakkiya.S


mvp_badge
MVP
Solution

Hi Vivek,

than you can simple use regex  and find it .


https://www.cluemediator.com/find-urls-in-string-and-make-a-link-using-javascript


const string = "hei dude, check this link http:://google.com and http:://youtube.com"
const matches = string.match(/\bhttp?::\/\/\S+/gi);
console.log(matches);

Hope this will help you.

Regards

Rahul

mvp_badge
MVP

Hi Vivek,

you can do in simple way-

Take one expression and link use it as below pic-

and on link you can nevigate on other pages or site.

Hi Rahul

Thanks for your reply. But "My name is Vivek https://www.google.com" is a complete text which is saved in database. In addition to it, the url part can be present in any location of the text for example the string can also be "My name is Vivek https://www.google.com. I am working on OS". The requirement is to make only the url part as link. Do let me know if any further information required.


Thanks

mvp_badge
MVP
Solution

Hi Vivek,

than you can simple use regex  and find it .


https://www.cluemediator.com/find-urls-in-string-and-make-a-link-using-javascript


const string = "hei dude, check this link http:://google.com and http:://youtube.com"
const matches = string.match(/\bhttp?::\/\/\S+/gi);
console.log(matches);

Hope this will help you.

Regards

Rahul

Hi Rahul. Thanks for you precious reply. I have implemented the same and achieved it for web app. Can you also please guide me how to implement the same scenario for Mobile apps as well. Thanks in advance
mvp_badge
MVP

Hi Vivek,

you can use Javascript widget on screen action  or can use script for it.

In script you can make a function who is return web URL and use this URL in a link.


Hope this will help you.


Hi Rahul. For building the above logic in mobile app I am facing little difficulty.

On ready client action of scree, I have called a javascript where I am trying to display url text as clickable url.

The container class which I am using to display the string is named as "News". Can you please guide me how to use above logic and bind it in my News container


Thanks

Solution

Hi Vivek Kumar,

You can use the below js in onready action

var string = "hei dude, check this link http:://google.com and http:://youtube.com"

var matches = string.match(/\bhttp?::\/\/\S+/gi);

document.getElementById($parameters.container).innerHTML ="<a href=https://www.google.com/> '"+matches+"'</a>";

console.log(matches);


Regards,

Ellakkiya.S


Thank you all for your cooperation. 

Regards 

Vivek Kumar 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.