473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3524


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mark | last post by:
Sorry, I'm a newbie to php ;) I was thinking about using php to write the script file, something like: <script type="text/javascript" src="http://insert_url_here.com/myScript.php"></script> ...
9
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
12
by: Radek Maciaszek | last post by:
Hi It's very interesting problem. I couldn't even find any inforamtion about it on the google. I think that the best way of explain will be this simple example: <html> <body> <script...
8
by: geoffdude | last post by:
Hi everyone, newbie here. I'm really close to finishing my zip code search filter thingy to return a specific message (ultimately a unique phone number for sales contact) after a form query (of...
11
by: dusk | last post by:
Hi, I'm very new to javascript, and I'm having trouble finding a way to display a string of divs without the code getting really messy. I have several different pages to write, each with about...
1
by: ll | last post by:
I'm currently working on a form which consists of a show and hide javascript. The toggle works fine, although when I click on submit, I would like the page to reload with the toggle (show/hide)...
7
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.