techknow
09-16-2011, 04:05 AM
Hey guys I know this might have been discussed before but i can't find it anywhere. I'm trying to write javascript with javascript.... simple right well the problem is in my script i have javascript writing the </script> line like this
<script type="text/javascript">
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun, thisp)
{
var len = this.length;
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}
var typeArray = function (x) {
document.writeln('<script type="text/javascript">observe(x);</script>');
}
var myArray = [1,2,3,4,5];
myArray.forEach(typeArray);
</script>
When this code is ran it ends at the first </script> tag and you see all the code after it as just text.
i need this code to work because the function observe(); is an observer and has to be in the code for each instance of x. but when the </script> tag is written, even inside the "" it ends the code. Is there any way to write the </script> tag inside of javascript without ending the code??
<script type="text/javascript">
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun, thisp)
{
var len = this.length;
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}
var typeArray = function (x) {
document.writeln('<script type="text/javascript">observe(x);</script>');
}
var myArray = [1,2,3,4,5];
myArray.forEach(typeArray);
</script>
When this code is ran it ends at the first </script> tag and you see all the code after it as just text.
i need this code to work because the function observe(); is an observer and has to be in the code for each instance of x. but when the </script> tag is written, even inside the "" it ends the code. Is there any way to write the </script> tag inside of javascript without ending the code??