Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript script tag in a JavaScript String
    text
    copied!<p>I have the same issue as here:</p> <p><a href="https://stackoverflow.com/questions/1659749/script-tag-in-javascript-string">Script tag in JavaScript string</a></p> <p>However I can not resolve the issue with the proposed solutions. I'm using datatables plugin for jquery. I tried different solutions from above thread but none work. I get a "$ is not defined" error.If I set var html to like "test" it works fine. The script in the String inserts a ActiveX control (IE) or plugin (FF) and displays data from database. In below code the var html somehow breaks the script:</p> <pre><code>function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { var dataURL = "'data:chemical/smiles," + aData[0] + "'"; var html = '&lt;script type="text/javascript"&gt;' + 'cd_insertObject("chemical/x-daylight-smiles", 182, 172,' + '"CDCtrl' + iDisplayIndexFull + '","","True","False","True",' + 'dataurl='+ dataURL + ');&lt;/scr' + 'ipt&gt;'; $('td:eq(0)', nRow).html(html); // here $ causes an error return nRow; } </code></pre> <p>Note that I also tried to escape all &lt; and > also in the opening script tag. Same issue. Any ideas how to solve?</p> <p>EDIT:</p> <p>Found solution but can't answer my own question so here it is:</p> <p>jQuerys .html() function strips away script tags. I found that in the comments the documentation for .html().</p> <p>Another issue is that the 3rd party function cd_insertObject uses document.write().</p> <p>My solution was to copy+paste cd_insertObject but instead of using document write i return a string and then i put this string in </p> <pre><code>$('td:eq(0)', nRow).html(html); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload