2

Environment: Visual Studio 2008 SP1, ASP.NET and JavaScript

I'm trying to do a quick document.write test but as soon as I add script tags Visual Studio editor doesn't like it. Specifically, the closing script tag? I get those squiggly lines as soon as I enter the closing </script> tag

<html><head></head><body>
    <script type='text/javascript'>
      document.write('<html><head><script></script></head><body></body></html>');
    </script>
</body>
</html>
Rod
  • 14,529
  • 31
  • 118
  • 230

2 Answers2

3

Use:

document.write('<html><head><script><\/script></head><body></body></html>');
Note the `\`, here ------------------^

Another option is to split the string, so that it's not a exact tag:

document.write('<html><head><script></sc' + 'ript></head><body></body></html>');

Here's a reference explaining why it's needed, and other options:

Anyways, why are you writing a whole document into the <body>?

Community
  • 1
  • 1
Ian
  • 50,146
  • 13
  • 101
  • 111
  • not production stuff...just testing. Thanks. Why doesn't the other closing tags need it? – Rod Apr 17 '13 at 16:59
  • Well, I think it's because that string/code is currently inside of a ` – Ian Apr 17 '13 at 17:27
3

I am not familiar with Visual Studio, but I can tell that there are some errors on your HTML architecture, You shouldn't re-insert <html><head><body> if it is already in the HTML document, also try to escape the slash:

<html><head></head><body>
    <script type='text/javascript'>
      document.write('<script>alert("hello");<\/script>');
    </script>
</body>
</html>

If alert hello works then you are in the good track

multimediaxp
  • 9,348
  • 13
  • 49
  • 80