0

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.

0

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

1 Comment

I could solve the issue by splitting the closing script tag. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.