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>
asked Jul 28, 2015 at 17:54
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).

answered Jul 28, 2015 at 17:58
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.

answered Mar 27, 2016 at 19:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.