javascriptoutlookhtml-emailvml

How to extract href link inside VML (outlook code) in HTML Email using javaScript?


To extract "href" and "src" inside HTML Email, I used below code in console log in browser. It extract "href" and "src" from non outlook code only.

var urls=$$('a');
for(url in urls){
console.log("%c#"+url+" > %c"+urls[url].innerHTML +" >> %c"+urls[url].href,"color:red;","color:green;","color:blue;");
}

But I need to extract "href" and "src" from VML(Outlook code) also. See below VML code for detail.

<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" style="height:50px; v-text-anchor:middle; width:460px;" arcsize="45%" strokecolor="#db2b91" href="**http://somewebsite.com/**" strokeweight="4pt" fillcolor="#db2b91">
<w:anchorlock/>
<center>
<table width="455" align="center" valign="bottom" border="0" cellspacing="0" cellpadding="0" style="border-collapse: collapse; border-spacing: 0; mso-table-lspace: 0px; mso-table-rspace: 0px;"><tr><td align="center" valign="middle" style="font-family: Arial, sans-serif; font-size:16px; line-height:20px; font-weight: bold; vertical-align: middle; padding: 5px 0px 13px 0px; color: #ffffff;">Button text</td> </table>
</center>
</v:roundrect>
<![endif]--> 

Solution

  • You can access those elements using jQuery or pure Javascript once they are attached to the DOM. Note, this <!--[if mso]> is specific to outlook and will be attached to DOM only in those environments. So you can not access them outside outlook with the <!--[if mso]> condition.

    Now, you can select any vml elements by jQuery as below:

    $('v\\:roundrect')
    

    Or, by Javascript,

    document.getElementsByTagName('v:roundrect')
    

    Hope this helps.