ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

jQuery plaintext to hyperlink issue

(1/3) > >>

Asudem:
Greetings all,

I am modifying some open source software to better suit my needs. This line right here in the software displays the time-stamp, username, and message of a currently chatting user. However, it appears that text is in plaintext and not an HTML element.

What I would like to do is something similar to this which converts plaintext links to actual hyperlinks. The messages sent through ajax, however, don't appear to be html elements/objects, so I can't just modify the HTML of the message.

Any advice on how I should modify the software to best suit my needs?

Any help would be greatly appreciated and thank you in advance!

Deozaan:
Can't you run that regex code on the "text" variable from that highlighted line of code?

Specifically, use:


--- Code: Javascript ---// Set the regex stringvar regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig// Replace plain text links by hyperlinkstext = text.replace(regex, "<a href='$1' target='_blank'>$1</a>");
Between lines 154 and 155.

Asudem:
Can't you run that regex code on the "text" variable from that highlighted line of code?

Specifically, use:


--- Code: Javascript ---// Set the regex stringvar regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig// Replace plain text links by hyperlinkstext = text.replace(regex, "<a href='$1' target='_blank'>$1</a>");
Between lines 154 and 155.
-Deozaan (June 10, 2016, 04:24 PM)
--- End quote ---

Sadly no, the results are literal:
<a href='http://www.google.com' target='_blank'>http://www.google.com</a>
--- End quote ---

Deozaan:
Sounds like you need to find out where the code escapes the HTML characters and un-escape it.

Asudem:
Sounds like you need to find out where the code escapes the HTML characters and un-escape it.
-Deozaan (June 10, 2016, 07:03 PM)
--- End quote ---
I am slightly new to javascript, but I think I have a fairly good basic grasp of reading it. I believe the escaping occurs somewhere here, not 100% how though...

Navigation

[0] Message Index

[#] Next page

Go to full version