为什么 document.write 不再为我工作?
我正在 DotNetNuke 工作,但这似乎并不是严格意义上的 DNN 问题。
我在名为 FormatEmail 的模块中使用 DNN 提供的方法,该方法使用 document.write 写出电子邮件,如下所示:
<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>
我刚刚安装了 DNN 5,我知道它包括 jQuery 以及代码库的其他附加内容。 jQuery 会阻止 document.write 代码工作吗?
DNN 是否应该使用另一种方法来隐藏来自机器人的文本?
我应该停止使用此方法来隐藏我的电子邮件地址吗?
更新: 该页面未使用 xhtml。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道是否发生了这种情况,但是如果您的网站告诉浏览器它是严格的 XHTML,则
document.write
和document.writeln
将不起作用。 我相信要发生这种情况,您必须使用严格的 DOCTYPE 并将Content-Type
标头设置为application/xml+xhtml
而不是text/html
(许多服务器下的默认设置)。 这是因为以这种方式操作 DOM 可能会破坏它。 例如,如果我将以下内容放在经过验证的网页中:该文档将经过验证并且符合 XHTML,但在大多数浏览器中不起作用。
另一种方法是创建一个 DOM 节点,在其中插入电子邮件地址,并在页面加载时插入它。 例如:
或者,当您设置了 jQuery 时:
I don't know if this is what happened, but
document.write
anddocument.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 theContent-Type
header toapplication/xml+xhtml
rather thantext/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: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:
Or, as you have jQuery set up:
我想我在 DNN bug 跟踪器中找到了具体的答案:
输出应该是:
这似乎解决了我的网站(没有运行 XHTML)的问题。
该错误位于此处。
I think I found the specific answer in the DNN bug tracker:
the output should be:
This seems to fix the issue for my site (which wasn't running XHTML).
The bug is located here.
杰夫,
您确实找到了正确的解决方案,但说实话,我不太确定这样做的好处。 是的,电子邮件可能会被删除,但这个过程完全是多余的,至少在我看来是这样。 无需运行 JavaScript,只需呈现电子邮件链接即可。
这只是我为您手头的具体问题支付的 0.02 美元。
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.