简体   繁体   中英

generate html coding from javascript in c#

I'm doing html to well formed html in c#, all the process completed except javascript, please help to achive this:

my html has javascript for ex:

<html><body><b>
 <script type='text/javascript'>
 <!--
 var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
 var path = 'hr' + 'ef' + '=';
 var addy21908 = 'fr&#97;nch&#97;n' + '&#64;';
 addy21908 = addy21908 + 'sph' + '&#46;' + 'c&#111;m' + '&#46;' + 'sg';
 document.write('<a ' + path + '\'' + prefix + ':' + addy21908 + '\'>');
 document.write(addy21908);
 document.write('<\/a>');
 //-->\n </script><script type='text/javascript'>
 <!--
 document.write('<span style=\'display: none;\'>');
 //-->
 </script>This email address is being protected from spambots. You need JavaScript enabled to view it.
 <script type='text/javascript'>
 <!--
 document.write('</');
 document.write('span>');
 //-->
 </script></b></a></body></html>

how to get exact html input from above coding file? my expecting output like:

<a href="mailto:franchan@sph.com.sg"><b>franchan@sph.com.sg<span style='display: none;'>This email address is being protected from spambots. You need JavaScript enabled to view it.</span></b></a>

currently i am and "SGML" reader, XML writer for convert well formed HTML

Regards, thanks in advance,

saran

I suggest something like this

Live Demo

<script type='text/javascript'><![CDATA[
window.onload=function() {
  var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
  var addy88710 = ['fr&#97;nch&#97;n','&#64;','sph','&#46;','c&#111;m','&#46;','sg']
  var link = document.createElement("a");
  link.href=prefix + ':' + addy88710.join("");
  link.innerHTML=addy88710.join("");
  var span = document.getElementById("x");
  span.innerHTML="";
  span.appendChild(link);
}  
//]]></script>
 <span id="x">This email address is being protected from spambots. You need JavaScript enabled to view it.<span>

if you are trying to protect the emails, another simple solution is to create an image of the email on the fly and place it where the email text has to come, so it can't be caught by spammers. maybe alter the image so that ocr cant also read it easily.

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