document.print in XHTML

P

Pygmalion

I am using a ultra-simple PHP counter, that counts number of visits in
a plain txt file counter.txt, e.g.

index 10
pictures 8
cv 6

To display the number of visits, I use this combination:

<script type="text/javascript" src="counter.txt"></script>
....
Number of visits: <script type="text/
javascript">document.write(pictures)</script>

This ultra-simple thing works perfect in HTML, but not in XHTML, since
XHTML does not support document.write any more. Is there a way around
for this problem?

Thanks, Marko.
 
N

news.virginmedia.com

Pygmalion said:
I am using a ultra-simple PHP counter, that counts number of visits in
a plain txt file counter.txt, e.g.

index 10
pictures 8
cv 6

To display the number of visits, I use this combination:

<script type="text/javascript" src="counter.txt"></script>
...
Number of visits: <script type="text/
javascript">document.write(pictures)</script>

This ultra-simple thing works perfect in HTML, but not in XHTML, since
XHTML does not support document.write any more. Is there a way around
for this problem?

Thanks, Marko.

I think the way around this is to use document.createTextNode(pictures)
Not sure if this is correct but just a suggestion.
 
P

Pygmalion

I think the way around this is to use document.createTextNode(pictures)
Not sure if this is correct but just a suggestion.

I figured that myself. But it seems that createtextnode won't take
variable as an argument!

Marko
 
N

news.virginmedia.com

Pygmalion said:
I figured that myself. But it seems that createtextnode won't take
variable as an argument!

Marko

Where do you get this info?

Works for me in IE, try this in your browser:

<SCRIPT>
var pictures= 8;
var text = document.createTextNode(pictures);
document.body.appendChild(text);
</SCRIPT>


ALso what you say doesn't really make sense re: " XHTML does not support
document.write ".
I say this because document.write is a javascript method and xhtml doesn't
really have anything to do with javascript.
SO where does this come from?
 
E

Evertjan.

Dave wrote on 29 aug 2010 in comp.lang.javascript:

W3S:
"Does document.write work in XHTML?

No. Because of the way XML is defined, it is not possible to do tricks like
this, where markup is generated by scripting while the parser is still
parsing the markup."

But that does not include open();write();close() after the parser is done,
like in the OQ's "onload =".

Does the definition of XML really contain the "way" the parser should work,
or just the results?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top