Why doesn't document.write work anymore for me?
I work at DotNetNuke but this is not really a strictly DNN problem.
I am using the provided DNN method in my module called FormatEmail which uses document.write to check out the email, 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 document.write from running?
Should DNN use a different method to hide text from bots?
Should I stop using this method as a mask for my email addresses?
Update: The page does not use xhtml.
a source to share
I think I found a 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>
It looks like the problem is with my site (which was not running XHTML).
The error is here .
a source to share
I do not know if this has happened, but document.write
and document.writeln
will not work if your website tells the browser strict XHTML. I believe you need to use a strong DOCTYPE to do this and set the title Content-Type
to application/xml+xhtml
, not to text/html
(the default on many servers). This is because manipulating the DOM in this way can break it. For example, if I put the following half down on the checked webpage:
<script type="text/javascript">
<!--
document.write("</body>");
// -->
</script>
The document will validate and comply with the XHTML requirements, but will not work in most browsers.
An alternative is to create a DOM node where the email should be inserted and insert it on page load. For instance:
<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, since you have jQuery installed:
<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>
a source to share