Output Javascript document.write in XSL

房东的猫 提交于 2019-12-11 06:52:43

问题


I'm having major trouble to output a document.write() javascript through my XSL page. (It's part of a 3rd party external tracking code snippet)

My desired output is:

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

An this is my complete Code:

<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>

I've tried several things outoutting the document.write() element...with the above <xsl:text disable-output-escaping="yes"> not-working solution, the html gets outputted corrupted (two </script> tags)

--> How to output the document.write with the script tags correctly?


回答1:


Which browsers do you target? Mozilla browsers like Firefox or SeaMonkey are known not to support document.write in the HTML result of a client-side XSLT transformation: https://developer.mozilla.org/en/docs/XSL_Transformations_in_Mozilla_FAQ#What_about_document.write.3F



来源:https://stackoverflow.com/questions/20073158/output-javascript-document-write-in-xsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!