1

Is it possible to open and close a script tag inside another script tag?

Example

<script type="..." src="...">
code here
<script type="!!!" src="!!!">
code also here
</script>
</script>
1
  • 1
    Why would you even want that? Commented Jul 28, 2015 at 18:01

2 Answers 2

1

No

If the parent script tag is for javascript then child <script... is invalid javascript (you can't have html inside javascript).

Sign up to request clarification or add additional context in comments.

Comments

1

If you put a <script> tag between a <script> and </script>, that script then will be treated as a JavaScript expression.

In most cases, that means it generates an error message like ...

Uncaught SyntaxError: Unexpected token <

... or ...

SyntaxError: expected expression, got '<'

However, it doesn't generate an error per se. For example, consider the following code :

console.log('BEFORE');
var script = 0; var bool = 1 <script> 2;
console.log(bool);
console.log('AFTER');

This doesn't produce a code, because 1 <script> 2 is evaluated as this :

  1. 1
  2. is smaller than
  3. script
  4. is greater than
  5. 2

Because script exists as a variable, that doesn't produce any error. In the code here-above, console.log(bool); outputs false.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.