javascript - The string "</script>" in an array is interpreted, is there a workaround? -


this :

<script type="text/javascript"> var = new array("</script>"); alert(a); </script> 

...doesn't work expected (by me @ least). string "</script>" interpreted end of script though it's in quotes. please see these jsfiddles :

http://jsfiddle.net/rybts/

http://jsfiddle.net/pb73z/

the first declares first element of array in normal way while second declares in compact form. in both cases, browsers (chrome, ff, ie) stop script @ "</script>" , never alert.

it behaves same way whether using quotes or double quotes.

is expected ? there workaround?

edit: all, i'll escape backslash. sorry couldn't accept everyone's answer, accepted first one, everyone.

the link provided juhana explains behavior:

all html parsed before text nodes in element passed js engine, </script> gets no special treatment being inside js string literal

you escape / character:

<script type="text/javascript"> var = new array("<\/script>"); alert(a); </script> 

here's updated fiddle.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -