简体   繁体   中英

How to change the entered text as hyperlink in the textbox?

How to display the text as hyperlink if the user entered in the text box...

For example if the user entered the text as

"my website name is google.com"...and submit it,

i have to show that text as "my website name is google.com "

Is there any plugin available for this or any simple script is enough?

function replaceURLWithHTMLLinks(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp,"<a href='$1'>$1</a>"); 
}

Thanks to: How to replace plain URLs with links?

This is usually called "linkify" which I guess is a bit difficult to Google for if you don't know that.

Here is a jQuery plugin that will do this for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM