javascript - The string "</script>" in an array is interpreted, is there a workaround? -
this question has answer here:
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 :
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
Post a Comment