...

View Full Version : script in script, is it possible?



d52477001
06-02-2003, 12:48 PM
Hi,

I have a problem. I got a hit counter from Statsmachine.com. It requires that i add this code:

<script src="http://www.statsmachine.com/cgi-bin/counter/382/38252.cgi"></script>

in the head of every page i want logged. Now, i don't want to add a count when i access the page, so i used this method:

http://www.irt.org/script/1014.htm.

This means that i would have to put the script counter code in a <script>...</script>. It seems that this is not possible. Is there another solution that i could use?

I was thinking that maybe there is a way to put the src= in the script, instead of in the tag. Then it should work....


d52477001

joh6nn
06-03-2003, 01:51 AM
you can do this:
<script>document.write('<script src="http://www.statsmachine.com/cgi-bin/counter/382/38252.cgi"></sc' + 'ript>')</script>

that should do what you want. you need to be sure to separate that </script> tag the way i did (in bold), because otherwise, the javascript interpreter, will get confused, and cause an error

liorean
06-03-2003, 02:26 AM
Actually, it's not "</script>" that causes the problem, it's "</". This is easily corrected by escaping it using "<\/".

The reason for this is that the script is a CDATA containing element, and since no tags inside it are parsed, the first end tag must be the end of the CDATA block. (Basic SGML). This is not the case for XML, where no element have inherent CDATA blocks. There you must use explicit CDATA blocks (<![CDATA[ to ]]>) to be able to use the characters "<" and "&amp;" in scripts at all. Also, if you in XML use comments, you can not allow them to contain "--" since that ends the comment data. XML parsers are allowed to just ignore all comments, however, and then the script parser won't have anything to parse at all.

d52477001
06-04-2003, 02:18 PM
Yep, that did the trick... thanks!

I now only have the problem that if the cookie is found, it does not display the counter. It needs to have the

<script src="http://www.statsmachine.com/cgi-bin/counter/382/38252.cgi"></script>

...executed to show the counter. Yet, if the script is executed, then it is added to the counter...

d52477001

joh6nn
06-05-2003, 02:06 AM
i think that's something that you'll need to take up with the counter's author

d52477001
06-05-2003, 07:41 PM
yeah i did that and i got the location of the js file where the count is stored. So now my problem is solved. thanks.

d52477001



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum