简体   繁体   中英

Append code having multiple single multi quotes

I have to append the codes below on body but when I am doing this onReady , I am getting this error:

unterminated string literal

Below in code that I have appended:

jQuery('body').append('
    <!--
        Start of DoubleClick Floodlight Tag: Please do not remove
        This tag must be placed between the <body> and </body> tags, as close as possible to the opening tag.
        Creation Date: 10/12/2015
    -->
        <script type="text/javascript">
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.write(\'<iframe src="https://338333293.fls.doubleclick.net/activityi\' + a + \'?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
        </script>
        <noscript>
        <iframe src="https://333383293.fls.doubleclick.net/activityi;src=3383293;?" width="1" height="1" frameborder="0" style="display:none"></iframe>
        </noscript>
    <!-- End of DoubleClick  -->
');

I have done accroding to this StackOverflow Suggestion

But this is not working for me

For this ther are multiple ways:

First:

"Hello World"
+"Yo it's amazing"
+'Yes I "Love" it';

Second: Use `` (template)

Hello World Yo it's amazing Yes I "Love" it

Your code should be

//Create Html with proper concatenation 
var html='<!--Start of DoubleClick Floodlight Tag: Please do not remove This tag must be placed between the <body> and </body> tags, as close as possible to the opening tag. Creation Date: 10/12/2015-->';
html+='<script type="text/javascript">';
html+='                    var axel = Math.random() + "";';
html+='var a = axel * 10000000000000;';
html+='document.write(\'<iframe src="https://338333293.fls.doubleclick.net/activityi\' + a + \'?" width="1" height="1" frameborder="0" style="display:none"></iframe>\');';
html+='</script>';
html+='<noscript>';
html+='<iframe src="https://333383293.fls.doubleclick.net/activityi;src=3383293;?" width="1" height="1" frameborder="0" style="display:none"></iframe>';
html+='</noscript>';
html+='<!-- End of DoubleClick  -->';

//append html to dom
jQuery('body').append(html);

You had missed \\ after </iframe> use this and see

<script>
 jQuery('body').append('
                <!--
                Start of DoubleClick Floodlight Tag: Please do not remove
                This tag must be placed between the <body> and </body> tags, as close as possible to the opening tag.
                Creation Date: 10/12/2015
                -->
                <script type="text/javascript">
                var axel = Math.random() + "";
                var a = axel * 10000000000000;
                document.write(\'<iframe src="https://338333293.fls.doubleclick.net/activityi\' + a + \'?" width="1" height="1" frameborder="0" style="display:none"></iframe>\');
                </script>
                <noscript>
                <iframe src="https://333383293.fls.doubleclick.net/activityi;src=3383293;?" width="1" height="1" frameborder="0" style="display:none"></iframe>
                </noscript>
               <!-- End of DoubleClick  -->');
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM