I need a little assistance. I have to create a javascript string that contains more javascript that is then written to a div tag in the parent window. The code is as follows:
<script language="javascript" type="text/javascript">
var jstr2 = '';
jstr2 += '<script language="javascript">
';
jstr2 += 'function doPagingProducts(str) {
';
jstr2 += 'document.frmPagingProducts.PG.value = str;
';
jstr2 += 'document.frmPagingProducts.submit();
';
jstr2 += 'return false;
';
jstr2 += '}
';
jstr2 += '</script>
';
jstr2 += '
';
</script>
However the closing script tag in the created string actually close the javascript and I get errors such as:
Error: unterminated string literal
Line: 135, Column: 9 ( The </script> line before the end of the string.)
Source Code:
jstr2 += '
Is there any way I can prevent this issue..?
Many thanks for all your help.
Best Regards,
Paul
edit I finally solved this problem by extracting the final </script>
from the javascript string. I added a end tag where the script shows. Its messy, but it works. Many thanks for all your comments.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…