views:

56

answers:

3

When I try to run this script i get error in IE:

Unterminated string constant


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">

    <script language="javascript" type="text/javascript">
        var designDocumen;
        var designEditor;

        Initialize();
       function Initialize() {     
           designEditor = $get('myframe');

            designDocument = this.designEditor.contentWindow.document;            

            var outerHTML =
            "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'&gt;" +
            "<html xmlns='http://www.w3.org/1999/xhtml'&gt;" +
            "<head>" +
            "<title>Design Editor Frame</title>" +
            "<style type='text/css'>" +
            "body {background-color:Green;}"+
            "</style>" +
            "</head>" +
            "<body></body>" +
            "</html>";                      

           designDocument.open("text/html", "replace");
           designDocument.write(outerHTML);
           designDocument.close();               
        }           


    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>      

     <iframe id="myframe" height="500px" width="500px">
     </iframe>
    </div>
    </form>
</body>
</html>

How do I solve this? How to correct this string?

UPDATE: The problem is with the line:

"<title>Design Editor Frame</title>"

if i remove it, it works!

+3  A: 

You're missing a + after this line "body {background-color:Green;}".

Michael
samuel
+4  A: 

There's a + missing after "body {background-color:Green;}".

NickFitz
samuel
A: 

Four things;

  1. you declare designDocumen but use designDocument later
  2. you need to define the function Initialize() before you call it
  3. you need this script to be place at the bottom of your body element otherwise the iframe will not be available.
  4. you have no definition for $get so you will need to include the correct script library to use this method.
Matt Smith