...

View Full Version : problem with x.document.write('string');



battasrinivasa
09-20-2005, 01:48 PM
Hi everybody,

I am working with a javascript function for my javascript toolbar. With this function i am trying to find out all the javascript present in the page and preparing a string and trying to write that string in a new window.

But when i am trying to do this with my function it is not writing all the javascript found in that page. some part is not written in the new window.

do i need to use any flush or anything for this purpose.....?

You please have a look of my javascript function below:
--------------------------------------------------------
function viewJavascript()
{
var tagArray = window.document.getElementsByTagName('*');
var s ='';
var js='';
for(var i=0;i<tagArray.length;i++)
{
s = (tagArray[i].tagName).toLowerCase();
if((s=='script')&&((tagArray[i].language).toLowerCase()=='javascript'))
{
js='<br>'+js+tagArray[i].innerHTML;
}
}
var n = window.open('javascript');
n.document.write(js);
}
--------------------------------------------------------

thanks in advance

batta

nikkiH
09-20-2005, 02:04 PM
Let's see if it even got it in the first place.

js='<br>'+js+tagArray[i].innerHTML;
alert(js);

Add that alert in there.
Does the js variable even have all the script in it?

battasrinivasa
09-20-2005, 02:16 PM
hi
when i add

alert(js);

in js string variable i am able to see all the javascript but the problem is there only.

that java script also contatins the below things

------------------------------
<!--

//-->
-----------------------------

with in this the java script is coming.

so in html page the above one is comment. so it is not showing anything

can you tell me how to remove these things

thanks
batta

nikkiH
09-20-2005, 03:51 PM
Stop putting them in the script. ;)
They aren't needed any more. They're for browsers from 10 years ago that didn't understand the script element.

If you want to keep them for some odd reason, you'd need to write some sort of regular expression to parse them out with the string replace function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum