javascript - SyntaxError: unterminated string literal <script>...</script> tag not working within a string variable -


please code.

var id = 1; var htmltext = '<div id="horizontaluserpopup"><ul id="tabs1" class="rtabs"></ul><div class="panel-container"><div id="view1"><script>viewminiprofile("'+id+'",this);</script></div><div id="view2"></div><div id="view3" style="display:none;">blah blah blah</div><div id="view4" style="display:none;">444444</div></div></div>'; $('#contents').html(htmltext); 

above code getting following error -

enter image description here

if remove </script> working fine. please check , let me know.

edit:

complete code -

function modelinfo(id, username) {                 var pageurl = $('#pageurl').val();                 $('#model-popup-box1 h3').addclass('newsfeed');                 var content_area = $('#model-popup-content1');                 content_area.html('please wait...');                 $('#model-popup-box-title1').html('about ' + username);                 $('#model-popup-body1').show();                  content_area.html('<div id="horizontaluserpopup"><ul id="tabs1" class="rtabs"></ul><div class="panel-container"><div id="view1"><script>viewminiprofile("'+id+'",this);</script></div><div id="view2"></div><div id="view3" style="display:none;">blah blah blah</div><div id="view4" style="display:none;">444444</div></div></div>');                  var innerhtml = "<li><a href=\"#view1\" id='miniprofile-view1' onclick=\"viewminiprofile('"+id+"',this)\">mini-profile</a></li>" +                         "<li><a href=\"#view2\">tokens</a></li>" +                         "<li><a href=\"#view3\">notes</a></li><li><a href=\"#view4\">pm logs</a></li>";                  var ul = document.getelementbyid("tabs1");                 ul.innerhtml = innerhtml;                   $('#horizontaluserpopup').responsivetabs({                     rotate: false,                     startcollapsed: 'accordion',                     collapsible: 'accordion',                     sethash: true,                     disabled: [4, 5]                 });              } 

i'm going assume quoted code in script tag, this:

<script> // ...stuff here... $('#contents').html('<div id="horizontaluserpopup"><ul id="tabs1" class="rtabs"></ul><div class="panel-container"><div id="view1"><script>viewminiprofile("'+id+'",this);</script></div><div id="view2"></div><div id="view3" style="display:none;">blah blah blah</div><div id="view4" style="display:none;">444444</div></div></div>'); // ...stuff here... </script> 

if so, problem outer script tag terminated in middle of string, because html parser in browser doesn't interpret javascript code, scans through looking </script> figure out tag ends. code gets handed javascript parser is

$('#contents').html('<div id="horizontaluserpopup"><ul id="tabs1" class="rtabs"></ul><div class="panel-container"><div id="view1"><script>viewminiprofile("'+id+'",this); 

...which indeed have unterminated string literal.

you can fix by:

  1. putting javascript code in .js file , linking it, or

  2. putting backslash before / in ending script tag in string:

    $('#contents').html('...<script>...<\/script>...'); 

    the \ prevents browser's parser seeing sequence </script>, , doesn't think script ended there. in javascript string, however, \/ /.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -