Can one divert or hide document.write output?

G

Geoff Wilkins

I am using <SCRIPT src=...> to import a Javascript routine from a remote
source. I am then using some of the variables given values in the
routine, in my own Javascript..

Unfortunately the routine also outputs to the page using document.write.
I don't want this output. Any ideas how I can get rid of it?
 
M

Martin Honnen

Geoff said:
I am using <SCRIPT src=...> to import a Javascript routine from a remote
source. I am then using some of the variables given values in the
routine, in my own Javascript..

Unfortunately the routine also outputs to the page using document.write.
I don't want this output. Any ideas how I can get rid of it?

I am not sure you need that as you could take the script from the src
and rewrite it as necessary but if needed you can disable document.write
temporarily to a function doing nothing and then restore it later:

<html>
<head>
<title>disabling document.write</title>
<script type="text/javascript">
function disableDocWrite () {
document.oldDocumentWrite = document.write;
document.write = function () {};
}
function enableDocumentWrite () {
document.write = document.oldDocumentWrite;
}
disableDocWrite();
</script>
<script type="text/javascript">
// this would be the external script to be loaded with
// script src, to have a complete example I have simply used
// an embedded script here
function getGOD () {
var GOD = 'Kibo';
document.write('All praise ' + GOD + '.');
return GOD;
}
</script>
<script type="text/javascript">
var GOD = getGOD();
alert(GOD);
enableDocumentWrite();
</script>
</head>
<body>
<h1>document.write test</h1>
<p>
<script type="text/javascript">
document.write('Kibology for all.');
</script>
</p>
</body>
</html>
 
G

Geoff Wilkins

Martin Honnen said:
I am not sure you need that as you could take the script from the src
and rewrite it as necessary

The problem is that I want the values assigned to the variables at the
remote location
but if needed you can disable document.write temporarily to a function
doing nothing and then restore it later:

Great - this is just what I wanted. I thought that there must be some
way of doing it. Many thanks.
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top