0

I have the following namespace defined containing the DefaultHead : member which is having the list of script tags I need to load

but when I try to put it as follows it gives it above exception at the DefaultHead:'

I am not understanding how to solve this.

var PortalDemoSidebar = {
    DefaultHead:'<script src="chrome://portal_demo/content/scripts/mainPage.js"></script>\
        <script src="chrome://portal_demo/content/scripts/jquery-1.5.1.min.js"></script>\
        <script src="chrome://portal_demo/content/settings/api_url.js"></script>\
        <script src="chrome://portal_demo/content/scripts/utilities.js"></script>\
        <script src="chrome://portal_demo/content/scripts/api_calls.js"></script>\
        <script src="chrome://portal_demo/content/scripts/jquery.xml.js"></script>\
        <script src="chrome://portal_demo/content/scripts/history.js"></script>\
        <link href="chrome://portal_demo/content/style/main_page.css" rel="stylesheet" type="text/css"></link>',    
Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
komal
  • 1
  • 1
  • 1
  • 3
    Maybe the browser is seeing the `` and terminating the script there? Try splitting the string, i.e., `...<' + '/script>...` – Casey Chu Jun 11 '11 at 13:17

1 Answers1

4

There are two possible issues here.

First of all you have a multi-line string literal, which is not supported. A string literal can't contain a line break. If you want to break up the string on separate lines, you have to terminate the string and start a new string on the next line, and use the + operator to concatenate them. Example:

var x = 'This is' +
  ' a long ' +
  'string';

The other thing is the HTML code inside the string. The browser doesn't parse the Javsscript code when it determines what's in the script tag, so when it encounters </script> in the string literal, it will assume that it's the end of the tag.

If you are using XHTML you can add a CDATA tag inside the script tag to tell the browser that there is no markup until after then end of the CDATA tag. Another way is to make sure that there are no </script> inside the string, which you can do by splitting the string in the middle of the tag: </scr'+'ipt>.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005