1

i have this code and this is not working

<script>
    dialogFun();
            function dialogFun(){

                var code="<div style='font-size: 12px' id='dialog'><script src='https://content.jwplatform.com/libraries/xyz.js'> </script><div id='jwplyr'>Loading the player...</div><script type='text/javascript'>jwplayer('jwplyr').setup({'file': 'http://content.jwplatform.com/videos/xyz-lusPHdHK.mp4','image':'http://content.jwplatform.com/thumbs/xyz-320.jpg'});</script></div>";


                console.log(code);
                $( "body" ).append( code );
            }
</script>

this is not working

6
  • 4
    What mean it's not working ? Commented Jan 19, 2017 at 9:08
  • 1
    Possible duplicate of Can't append <script> element Commented Jan 19, 2017 at 9:08
  • Notice you are using jQuery have you made sure you added the jQuery lib correctly ? Are you getting any errors in the console? Commented Jan 19, 2017 at 9:13
  • 1
    What do mean "not working"? You simply need to ESCAPE "/" of closing tags <\/script> Commented Jan 19, 2017 at 9:13
  • 1
    @Kyle Only escaping </script> is necessary, because </script> terminates the beginning <script>, even if it’s within a string. Commented Jan 19, 2017 at 9:15

1 Answer 1

4

ESCAPE the "/" of closing tags

<script>
    dialogFun();
            function dialogFun(){

                var code = "<div style='font-size: 12px' id='dialog'>"+
                "<script src='https://content.jwplatform.com/libraries/xyz.js'><\/script>"+
                "<div id='jwplyr'>Loading the player...</div>"+
                "<script type='text/javascript'>jwplayer('jwplyr').setup({'file': 'http://content.jwplatform.com/videos/xyz-lusPHdHK.mp4','image':'http://content.jwplatform.com/thumbs/xyz-320.jpg'});<\/script><\/div>";


                console.log(code);
                $( "body" ).append( code );
            }
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Should you always escape closing tags or is this a special case ?
@FrederickM.Rogers Only escaping </script> is necessary, because </script> terminates the beginning <script>, even if it’s within a string.
@FrederickM.Rogers for script tags are required

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.