views:

373

answers:

3

I'm working in DotNetNuke but this doesn't really seem to be strictly a DNN problem.

I am using a DNN provided method in my module called FormatEmail which uses document.write to write out an email like like so:

<script language="text/javascript">

<!--
  document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,119,101,98,109,105,110,64,97,116,101,110,118,101,108,100,116,46,111,114,103,34,62,119,101,98,109,105,110,64,97,116,101,110,118,101,108,100,116,46,111,114,103,60,47,97,62))
// -->

</script>

I just installed DNN 5 which I know includes jQuery among other additions to the codebase. Will jQuery stop the document.write code from working?

Should DNN be using another method to cloak text from bots?

Should I stop using this method as a way of cloaking my email addresses?

Update: The page is not using xhtml.

+4  A: 

I don't know if this is what happened, but document.write and document.writeln will not work if your site tells the browser it is strict XHTML. I believe that for this to happen, you have to use the strict DOCTYPE and set the Content-Type header to application/xml+xhtml rather than text/html (the default under many servers). This is because manipulating the DOM in this way could break it. For example, if I put the following half-way down a validated web page:

<script type="text/javascript">
<!--
    document.write("</body>");
// -->
</script>

The document would validate and be XHTML compliant, but would not work in most browsers.

The alternative is to create a DOM node where the email address should be inserted, and to insert it when the page has loaded. For example:

<p>My email address is <span id="email"></span>.</p>
<script type="text/javascript">
<!--
    document.body.onload = function() {
        document.getElementById("email").textContent = String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,119,101,98,109,105,110,64,97,116,101,110,118,101,108,100,116,46,111,114,103,34,62,119,101,98,109,105,110,64,97,116,101,110,118,101,108,100,116,46,111,114,103,60,47,97,62);
    };
// -->
</script>

Or, as you have jQuery set up:

<p>My email address is <span id="email"></span>.</p>
<script type="text/javascript">
<!--
    $( function() {
        $("#email").text(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,119,101,98,109,105,110,64,97,116,101,110,118,101,108,100,116,46,111,114,103,34,62,119,101,98,109,105,110,64,97,116,101,110,118,101,108,100,116,46,111,114,103,60,47,97,62));
    } );
// -->
</script>
Samir Talwar
Firefox says im in quirks mode so I don't think its XHTML doing it. I will update the question with this info... but I may try your jQuery solution (editing DNN core... )
Jeff Martin
+2  A: 

I think I found the specific answer in the DNN bug tracker:

the output should be:

<script type="text/javascript">

//<![CDATA[
 document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,84,101,115,116,64,106,101,102,102,109,97,114,116,105,110,46,99,111,109,34,62,84,101,115,116,64,106,101,102,102,109,97,114,116,105,110,46,99,111,109,60,47,97,62))
//]]>

</script>

This seems to fix the issue for my site (which wasn't running XHTML).

The bug is located here.

Jeff Martin
A: 

Jeff,

You did find the right solution, but to be honest, I'm not really sure of the benefit of this. Yes, e-mails can get scraped, but this process is just downright overkill, at least in my opinion. There is no need to have javascript running, just to render an e-mail link.

That is just my $0.02 on your very specific matter at hand.

Mitchel Sellers
this should probably be in a comment... I have actually had several inquiries if the people who use my site's email is protected in this way, so I was glad to say it was. My modules have used this DNN provided method for some time and it was frustrating to see it suddenly stop working when I installed DNN 5.
Jeff Martin