javascript - 在 XSL 中输出 Javascript document.write

标签 javascript xml xslt xhtml document.write

我在通过我的 XSL 页面输出 document.write() javascript 时遇到了很大的麻烦。 (它是第 3 方外部跟踪代码片段的一部分)

我想要的输出是:

  document.write('<sc'+'ript src="'+'http'+(document.location.protocol=='https:'?'s':'')+'://'+ia_link+'"></sc'+'ript>');

这是我的完整代码:

<script language="JavaScript" type="text/javascript">

    var url="someurl.js";
    var blablabla="some-dynamic-values"; 
    var ia_link=url+'?parameter='+blablabla;

</script>

<script>
   <xsl:text disable-output-escaping="yes"><![CDATA[document.write('<script type="text/javascript" src="//:'+ia_link+'"></script>')]]></xsl:text>
</script>

<noscript>
  <img src="http://url.php?blablabla=some-dynamic-values" width="1" height="1" />
</noscript>

我已经尝试了一些超越 document.write() 元素的方法...使用上面的 <xsl:text disable-output-escaping="yes">无效的解决方案,html 输出已损坏(两个 </script> 标签)

-->如何正确输出带script标签的document.write?

最佳答案

您的目标浏览器是哪些?众所周知,Mozilla 浏览器(如 Firefox 或 SeaMonkey)不支持客户端 XSLT 转换的 HTML 结果中的 document.write:https://developer.mozilla.org/en/docs/XSL_Transformations_in_Mozilla_FAQ#What_about_document.write.3F

关于javascript - 在 XSL 中输出 Javascript document.write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20073158/

相关文章:

json - 有没有像 csv 或 json 这样的东西,但更图形化,更适合人类阅读?

xml - 将 Liquibase XML 转换为 YAML?

xml - 如何从第2或3页开始页码编号?

java - "Reverse"XSLT(解析和构建 XML DOM 的语言)

XSLT:将一个元素注入(inject)另一个元素

javascript - JavaScript 中的 Promise 与 Java 中的异常处理类似吗?

javascript - 为什么 draggable 不适用于动态创建的元素?

css - 玛根托 : how to properly move custom simple products options in the right column on product page?

javascript - epub3使用html + JS

javascript - Webpack 仅在特定文件中查找更改