469,140 Members | 1,157 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

Can one divert or hide document.write output?

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?

--
Best wishes,

Geoff Wilkins
Ge****@wordsmith.demon.co.uk
Jul 20 '05 #1
2 3323


Geoff Wilkins wrote:
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>
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
In message <40********@olaf.komtel.net>, Martin Honnen
<ma*******@yahoo.de> writes
Geoff Wilkins wrote:
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
it?
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.

<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>


Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Mark | last post: by
19 posts views Thread by dmiller23462 | last post: by
12 posts views Thread by Radek Maciaszek | last post: by
11 posts views Thread by dusk | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.