I am trying to include the following script in a variable.
<script type="text/javascript">//<![CDATA[Calendar.setup({
inputField : "datum",trigger : "f_btn1",onSelect : function() {this.hide() },dateFormat : "%Y-%m-%d "});//]]></script>*
var contentString ='<table><tr><td><input size="10" id="datum" /><button id="f_btn1">ddd</td></tr> </table> <script type="text/javascript">..see above script...</script>';
The browser generates an error in the line with </script>. I cannot place the script because it should be executed only if a window opens in google maps --> infowindow.open(map,marker1);
Is it generally possible to put the declaration of js in a variable? I have tried several combinations of commas and escape variations (\") but wasn't successful.
1 Answer 1
The browser will read the </script> tag inside the string, and assume that you're closing the JavaScript block entirely.
So if you write:
<script> var a = '</script>'; </script>
...it is not read as
<script>
var a = '</script>';
</script>
But as
<script>
var a = '
</script>'; </script>
Usually people solve this by just splitting up the tag and concatenating it:
<script> var a = '</scr' + 'ipt>'; </script>