How to find the HTTP links in HTML mail using regular expressions in JavaScript -


I am working on a mail client application. I want to show all the HTTP links as clickable hyperlinks.

I have noticed that some clients are sending an HTTP link without enclosing them inside the anchor tags. In this case I have failed to show those links as a clickable link.

My requirement is to get all the HTTP links in a HTML mail and need to change these links by applying these links within the anchor tag and I need to exclude links that already have anchor tag Or any tag in the source attribute.

Ex: Suppose that my HTML mail has the following text

  Input: "http://www.google.com/" & lt; A href = "http: \\ gmail.com" & gt; & Lt; / A & gt; After replacing  

I want to put the following

  Output:  

I think I can not directly look for patterns that start with http ... because it can also come in the form of src for any tag.

So can someone help me in solving these problems

Thank you in advance

SubBi

Check this:

 (function ($) {$ .fn.hyperlinkRegex = function (regex, target, ismailto) { Ismailto = ismailto || ($ (This) .textwith ($ (this) .text (regex == undefined || regex.source == '') {$ (this) .find ('a'). () {$ (This). ()); $ (This) .Parent (). (Function () {node = $ (this) .get (0); if (node. Normal) node. Enormalize () ;}}}}}}} Else {$ (this) .each (function () {elt = $ (this) .get (0) elt.normalize (); $ .each ($ .makeArray (elt.childNodes) , Function (i, node) {if (Node.nodeType == 3) {var searchnode = node while ((pos = searchnode.data.search (regex))> = 0) {match = searchnode.data.slice (pos) .mail (regex) [0] ; If (match.long == 0) break; var annode = do cument.createElement ('a'); var middlebit = searchnode.splitText (pos); var searchnode = middlebit.splitText (match.length); Var middleclone = middlebit.cloneNode (true); Anode.appendChild (middleclone); If (ismailto == true) {anode.href = "mailto:" + middleclone.nodeValue; } And {anode.href = middleclone.nodeValue; } Anode.target = Target; Searchnode.parentNode.replaceChild (Anode, Midbitta); }} And {$ (node) Hyperlink rijks (regex, target, ismailto); }})}) Refund $ (this); }}) (JQuery); 

Usage:

 // Original link var exp = / (\ b (| https | | ftp | file): \ / \ / [- A-Z0-9 + & @ ?! # \ /% = ~ _::,;] * [- AZ0-9 + and @ # \ /% = ~ _ |]) / ig; Node.hyperlinkRegex (exp, "_blank", incorrect); // Email XP = / (ABAA-0-9-9 ._% -] + @ [A-Z0-9- Ag.Akha · AJ-Z] {2,4} B. ) / IG; Node.hyperlinkRegex (exp, "_blank", true); 

Let me know that it resolves your problem


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -