What "trailing characters" usually guarantee that subsequent javascript will be launched?

Is there a sequence of characters that can be used after incorrect javascript code to ensure that the subsequent script will be executed?

The idea is that we have separate departments that write javascript code that will be placed on the same page. The β€œother” group is notorious for leaving bad code. Since my code will be in the footer (via site.master), what character set can I use to provide (or, more likely, more likely) my code?

Example

// > "" ; */ alert("this code will always run, regardless of what happens before..."); 
+4
source share
2 answers

Nothing is defined in EcmaScript itself. A syntactically invalid program does not start at all.

In HTML, </script><script> will close the current SCRIPT and open a new one, and failure of one content of the SCRIPT element for parsing will not cause the contents of the SCRIPT elements to not be parsed, since they are different programs.

If the previous content is always a line comment, as in your example, any line terminator will suffice, and EcmaScript line terminators will be

 U+A \n U+D \r U+D,U+A \r\n U+2028 Line separator U+2029 Paragraph separator 

in accordance with section 7.3 of the specification.

+6
source

While it is in its own script element, it should be in order, no matter what it was before.

Example | Source

+3
source

Source: https://habr.com/ru/post/1395507/


All Articles