V
V
Vadim2011-01-03 22:18:00
JavaScript
Vadim, 2011-01-03 22:18:00

How to write the result of document.write('34'); into a variable?

The question is that I need to write the result of executing document.write('34'); into a variable, and I googled and didn't find how to do it.
document.write('34'); comes to me from the server, so I can't change it in any way.
UPD:
I understand that this is fundamentally wrong, but

var a = open(&quot;POST&quot;, &quot;http://meteo.swamp.ru/js.php&quot;, false); <br/>
alert(a);

Outputs: object DOMwindow
That is, does it work?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
H
homm, 2011-01-03
@de_arnst

<script>
document.write = function(text) {
  alert(text);
}
document.write('34');
</script>

M
MT, 2011-01-04
@MTonly

You can get the result as a simple string and extract the desired part of it as a substring.

T
taviscaron, 2011-01-03
@taviscaron

I'm not familiar with js, but as an option, redefine
document.write = function(x) {return x;}
run the response through eval:
var x = eval (response)
and return the old write to its place.
It seems to be possible to do so.

E
Elkaz, 2011-01-04
@Elkaz

If only numbers come in, it makes sense to use the parseInt or parseFloat function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question