Email地址加密javascript版

2020年2月27日23:45:11Email地址加密javascript版已关闭评论 300 3124字阅读10分24秒

function getEmail(email)

{

    var r = "";

    for (i=0;i<email.length;i++)

    {

        r += "&#" + email.charCodeAt(i);

    }

    return r;

}


效果如下:

<!--Author:yao.cnblogs.com DateTime:2006-08-24 --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Email地址加密</title> <style type="text/css"> <!-- body { font-size: 12px; } --> </style> <script language="javascript" type="text/javascript"> function getEmail(email) { var r = ""; for (i=0;i<email.length;i++) { r += "&#" + email.charCodeAt(i); } return r; } function setClipboard(id) { var tb = document.getElementById(id); var copytext = tb.value; if (copytext!="") { if (window.clipboardData) { window.clipboardData.setData("Text", copytext); alert("已复制到剪贴板。"); } else if (window.netscape) { setClipboardNetscape(copytext); alert("已复制到剪贴板。"); } } return false; } function setClipboardNetscape(text){ var url = [ 'data:text/html;charset=utf-8;base64,PGJvZHk+PC9ib2', 'R5PjxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4KKGZ1', 'bmN0aW9uKGVuY29kZWQpe3ZhciBzd2ZfZGF0YSA9IFsKICdkYX', 'RhOmFwcGxpY2F0aW9uL3gtc2hvY2t3YXZlLWZsYXNoO2Jhc2U2', 'NCxRMWRUQjJ3JywKICdBQUFCNG5EUGdZbGpBd01qSTRNejAlMk', 'YlMkY5JTJGZTJaZkJnYUdhV3dNRE1uNUthJywKICdrTU10TjRH', 'ZGdaZ1NJTXdaWEZKYW01UUFFJTJCQm9iaTFCTG5uTXlDcFB6RW', '9oU0dJJywKICdQRnAlMkZBeHNEREJRa3BGWkRGUUZGQ2d1eVM4', 'QXlqSTRBRVVCaXkwVndBJTNEJTNEJwpdLmpvaW4oIiIpOwpkb2', 'N1bWVudC5ib2R5LmlubmVySFRNTCA9IFsKICc8ZW1iZWQgc3Jj', 'PSInLHN3Zl9kYXRhLCciICcsCiAnRmxhc2hWYXJzPSJjb2RlPS', 'csZW5jb2RlZCwnIj4nLAogJzwvZW1iZWQ+JwpdLmpvaW4oIiIp', 'Owp9KSgi', base64encode( encodeURIComponent(text) + '")</'+'script>') ].join(""); var tmp = document.createElement("div"); tmp.innerHTML = [ '<iframe src="',url,'"' ,' width="0" height="0">' ,'</iframe>' ].join(""); with(tmp.style){ position ="absolute"; left = "-10px"; top = "-10px"; visibility = "hidden"; }; document.body.appendChild(tmp); setTimeout(function(){document.body.removeChild(tmp)},1000); function base64encode(str){ var Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""); var c1, c2, c3; var buf = []; var len = str.length; var i = 0; while(i < len){ c1 = str.charCodeAt(i) & 0xff; c2 = str.charCodeAt(i+1); c3 = str.charCodeAt(i+2); buf.push(Chars[(c1 >> 2)]); if(i+1 == len){ buf.push(Chars[(c1 & 0x3) << 4],"=="); break; } buf.push(Chars[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]); if(i+2 == len){ buf.push(Chars[(c2 & 0xF) << 2],"="); break; } buf.push( Chars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)], Chars[(c3 & 0x3F)] ); i+=3; } return buf.join("") } } </script> </head> <body> <p><strong>Email地址加密</strong></p> <p> Email: <input name="email" type="text" id="email" size="50" /> <input type="button" name="Submit" value=" 加 密 " onclick="document.getElementById('export').value=getEmail(document.getElementById('email').value)"/>      <input type="button" name="Submit2" value=" 验 证 " onclick="document.getElementById('preview').innerHTML=getEmail(document.getElementById('email').value)"/>  <span id="preview" style="color:#FF0000"></span > </p> <p> 结 果: <input name="export" type="text" id="export" size="76" onclick="setClipboard(this.id)" onmouseover="javascript:this.select();" title="单击此处复制内容"/> </p> <p> </p> </body> </html>

[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]

继续阅读
编程十万个怎么办