Click to See Complete Forum and Search --> : The Ultimate Javascript Paradox


Helix
09-27-2003, 07:35 AM
Can somebody tell me what is wrong with the following string assignment?

s="<script></script>"


"Nothing", you'll say. Indeed, if you take the time to put the statement in a file and save it with a .js extension, the script successfully executes.
Then, why is it that my page is not working any more when I paste in this line??


<html>
<head>
<meta http-equiv="content-script-type" content="text/javascript">
<script type="text/javascript">
function blah()
{s="<script></script>"}
</script>
</head>
</html>

gil davis
09-27-2003, 08:22 AM
Your problem is that the browser parses the tag as an actual valid HTML tag and expects some script in between the tags. You have to break up the tag to prevent this action:

{s="<scr" + "ipt></scr" + "ipt>"}

Khalid Ali
09-27-2003, 08:24 AM
Originally posted by Helix
......... what is wrong with the following string assignment?
................

"Nothing", you'll say.
[/code]

No actually that assignment is wrong in javascripts case.

s = "<script><script>";

is correct but when you add / (forward slash) to it you wil have to escape it

so the correct code will be

s = "<script><\/script>";