...

View Full Version : How do you quote the string "</script>"



col2005
09-27-2005, 04:01 AM
Hi,

As the subject says, I'm having trouble quoting the text </script>

I have a method that uses single quote for quoting strings, e.g.

myMethod('some string param'); // I can't pass the string '<script>var a=0;</script>'

It throws an error unterminated string :(

any idea why?

TIA

Vladdy
09-27-2005, 04:13 AM
Use DOM methods to add script elements, not document.write:


var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'myScript.js';
document.getElementsByTagName('head')[0].appendChild(newScript);

felgall
09-27-2005, 10:23 PM
The simplest change is to escape it like this to stop the </script> being interpreted as end-of-Javascript:

'<script>var a=0;<\/script>'



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum