在 document.write 上使用 unescape 加载 javascript 有什么好处? [英] What is the advantage of using unescape on document.write to load javascript?

查看:22
本文介绍了在 document.write 上使用 unescape 加载 javascript 有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您必须添加以使用谷歌分析跟踪网页的代码如下所示:

The code that you have to add to track a web page with google analytics looks like:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXX");
pageTracker._trackPageview();
} catch(err) {}</script>

做这些行的好处是什么:

What's the advantage of doing these line:

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

与这些行相反:

document.write("<script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'></script>");

我编写了一些执行类似操作的代码(加载 javascript通过"文档写入),但它没有使用 unescape,我想知道我是否应该遵循 google-analytics 示例.

I wrote some code that does something similar (load javascript "via" document write) but it does not use unescape and I am wondering if I should follow the google-analytics example.

推荐答案

这意味着代码可以在 XML/XHTML 和 HTML 中工作,而不必与 CDATA 混淆

It means the code will work in XML / XHTML and HTML without having to mess with CDATA

这篇关于在 document.write 上使用 unescape 加载 javascript 有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆