473,761 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to view results of document.write( )?

Eli
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 it's being
written into the page.

Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?

Jul 23 '05 #1
14 4126

"Eli" <u1@zolx.com> wrote in message
news:g7******** *************** *********@4ax.c om...
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 it's being
written into the page.

Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?


call up the page in the browser.
that is what it writes.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004
Jul 23 '05 #2
Hal Rosser wrote:
"Eli" <u1@zolx.com> wrote in message
news:g7******** *************** *********@4ax.c om...
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 it's being
written into the page.

Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?

call up the page in the browser.
that is what it writes.


Do you ever actually test what you answer?

To the OP:
The simplest way is to add a textarea to the page, instead of
document.write (or in addition to), set the textarea's value to your
variable.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
Eli
On Wed, 10 Nov 2004 01:17:38 -0500, Randy Webb
<Hi************ @aol.com> wrote:
Hal Rosser wrote:
"Eli" <u1@zolx.com> wrote in message
news:g7******** *************** *********@4ax.c om...
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 it's being
written into the page.

Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?

call up the page in the browser.
that is what it writes.


Do you ever actually test what you answer?

To the OP:
The simplest way is to add a textarea to the page, instead of
document.wri te (or in addition to), set the textarea's value to your
variable.


Thank you. As it stands the code doesn't do a single document.write( )
of a variable, but numerous writes in conditionals, loops, etc.

I suppose it could be rewritten as such, however, if this is the best
way.

Jul 23 '05 #4
Eli wrote:
[...]
I suppose it could be rewritten as such, however, if this is the best
way.


Try loading in Firefox and use File -> Save as...
Cheers, Rob.
Jul 23 '05 #5
Eli wrote:
On Wed, 10 Nov 2004 01:17:38 -0500, Randy Webb
<Hi************ @aol.com> wrote:

Hal Rosser wrote:
"Eli" <u1@zolx.com> wrote in message
news:g7***** *************** ************@4a x.com...
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 it's being
written into the page.

Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?

call up the page in the browser.
that is what it writes.


Do you ever actually test what you answer?

To the OP:
The simplest way is to add a textarea to the page, instead of
document.writ e (or in addition to), set the textarea's value to your
variable.

Thank you. As it stands the code doesn't do a single document.write( )
of a variable, but numerous writes in conditionals, loops, etc.

I suppose it could be rewritten as such, however, if this is the best
way.


It is always best to make a single string and then do one document.write
than doing multiple document.write' s

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
On Wed, 10 Nov 2004 00:05:26 -0700, Eli <u1@zolx.com> wrote:
On Wed, 10 Nov 2004 01:17:38 -0500, Randy Webb
<Hi************ @aol.com> wrote:


[snip]
The simplest way is to add a textarea to the page, instead of
document.write (or in addition to), set the textarea's value to your
variable.


Thank you. As it stands the code doesn't do a single document.write( )
of a variable, but numerous writes in conditionals, loops, etc.

I suppose it could be rewritten as such, however, if this is the best
way.


If it's too much trouble to change your code, then change what the write
method does. :)

document.write = (function() {
/* Perform a one-time initialisation of the overriding
* function.
*
* This will hold the property name for the original
* write method so it can be called later.
*/
var old = '__write',
/* When this method is called, it is possible that the
* textarea used to hold the output has not been encountered
* yet, so it can not be addressed through the DOM. Until
* it is accessible, output is stored in the variable below.
*/
tmp = '',
/* This is the id of the textarea where output should
* be directed. Change it as you see fit.
*/
output = 'textarea-id',
/* This is text that should be appended to any text sent to
* the output textarea. You might just want to leave it as-is
* (a new line), but change this too if you want. Note that
* it won't affect what is actually written to the document.
*/
suffix = '\n',
/* Similar to the above, but prepended to the text. */
prefix = '';

/* Search for an identifier that is not currently used
* where the original function can be stored.
*/
while('undefine d' != typeof document[old]) {old += '__';}
/* Once found, add a reference to the original method. */
document[old] = document.write;

/* Now that the initialisation is complete, the function
* below overrides the original method.
*/
return function(str) {
/* Attempt to get a reference to the debugging
* textarea element.
*/
var o = document.getEle mentById(output );
/* Store the text in case the call above fails. */
tmp += prefix + str + suffix;
/* Write the text using the original method. */
document[old](str);

/* If the textarea could be found, we can begin preparations
* to use it in every call after this point. As we won't need
* to store the text any more, we can prevent that code from
* being called by substituting yet another function.
*/
if(output) {
/* Send the stored text to the textarea. If you want to use
* the textarea for other things, you might want to change
* this line from an assignment (=) to a concatenation (+=).
*/
output.value = tmp;
/* As we may have built up a lot of text,
* let's free some memory.
*/
tmp = null;
/* From now on, this whole process can be streamlined.
* As we now have access to the textarea element, text
* can be added to it directly.
*/
return function(str) {
output.value += prefix + str + suffix;
document[old](str);
}
}
};
})();

You'll probably have to change the string, output, and possibly the prefix
and suffix strings. Copy this code into a SCRIPT element in the HEAD
section of the document, and call document.write as normal. Depending
where your document.write calls are in respect to the debugging TEXTAREA
element, you may need to add a call at the end of your page - even just
document.write( '') - to flush the buffer.

If you use the writeln method, too, you can pretty much copy the above,
changing "write" to "writeln" where needed. The code is actually quite
compact - it's just the comments that make it so imposing.

Good luck,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7
Eli wrote:
On Wed, 10 Nov 2004 01:17:38 -0500, Randy Webb
<Hi************ @aol.com> wrote:
Hal Rosser wrote:
"Eli" <u1@zolx.com> wrote in message
news:g7******** *************** *********@4ax.c om...

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 it's being
written into the page.

Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?

call up the page in the browser.
that is what it writes.


Do you ever actually test what you answer?

To the OP:
The simplest way is to add a textarea to the page, instead of
document.wri te (or in addition to), set the textarea's value to your
variable.


Thank you. As it stands the code doesn't do a single document.write( )
of a variable, but numerous writes in conditionals, loops, etc.

I suppose it could be rewritten as such, however, if this is the best
way.


This doesn't work all that well, but it will show you the dynamic content (as
well as the script:

<button
onclick="window .open('javascri pt:opener.docum ent.documentEle ment.innerHTML. replace(/</g,
\'&\' + \'lt;\');');">V iew Dynamic Source</button>

Others can probably improve on this, but it's probably best to design your
script to output known HTML, rather than guessing and using some hack like
the above to try to make sure it's right.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #8
Eli wrote:
Is there a way that I can view what is being placed into the page,
instead of, or in addition to the javascript code?


I use the code below in my IE context menu. You could easily turn it into a
bookmarklet if you wanted to. It shows me the source exactly as IE sees it,
which is what I usually need:

var srcwin =
window.open('ab out:blank','src ','width=1200,h eight=900,top=0 ,left=0');
srcwin.document .open();
srcwin.document .writeln('<html ><body><form><t able width=100%
height=100%><tr ><td><textare a name="src" id="src"
style="width:10 0%;height:100%; "
wrap="off"></textarea></td></tr></table></form></body></html>');
srcwin.document .close();
srcwin.document .forms[0].src.value =
doc.getElements ByTagName('html ').item(0).oute rHTML;

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #9
Grant Wagner <gw*****@agrico reunited.com> wrote in message news:<41******* ********@agrico reunited.com>.. .
Eli wrote:
On Wed, 10 Nov 2004 01:17:38 -0500, Randy Webb
<Hi************ @aol.com> wrote:
Hal Rosser wrote:
> "Eli" <u1@zolx.com> wrote in message
> news:g7******** *************** *********@4ax.c om...
>
>>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 it's being
>>written into the page.
>>
>>Is there a way that I can view what is being placed into the page,
>>instead of, or in addition to the javascript code?
>>
>
>
> call up the page in the browser.
> that is what it writes.

Do you ever actually test what you answer?

To the OP:
The simplest way is to add a textarea to the page, instead of
document.wri te (or in addition to), set the textarea's value to your
variable.


Thank you. As it stands the code doesn't do a single document.write( )
of a variable, but numerous writes in conditionals, loops, etc.

I suppose it could be rewritten as such, however, if this is the best
way.


This doesn't work all that well, but it will show you the dynamic content (as
well as the script:

<button
onclick="window .open('javascri pt:opener.docum ent.documentEle ment.innerHTML. replace(/</g,
\'&\' + \'lt;\');');">V iew Dynamic Source</button>

Others can probably improve on this, but it's probably best to design your
script to output known HTML, rather than guessing and using some hack like
the above to try to make sure it's right.


You might try something like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>untitled </title>
<script type="text/javascript">
//<![CDATA[

var ptwin = null,
r = null,
gstr = '';

function plaintextwin()
{
if (null != r)
clearTimeout(r) ;
if (ptwin && !ptwin.closed)
ptwin.close();
var str = '';
for (var a = 0; a < arguments.lengt h; ++a)
str += arguments[a].concat('\n');
gstr = gstr.concat(str .replace(/(<[^/])/g, '\n$1').concat( '\n'));
ptwin = open('about:bla nk', 'ptwin',
'width=100,heig ht=100,left=20, top=50,scrollba rs,resizable');
ptwin.document. open('text/plain');
ptwin.document. write(gstr);
ptwin.document. close();
ptwin.focus();
r = setTimeout('ptw in.resizeTo(' + (screen.width * .95) + ',' +
(screen.height * .66) + ')',100);
}

document.write = plaintextwin;

s = '<span class="foo">hah </span><h4>Hello, World !</h4><br />';
document.write( s);
document.write( '<div class=vs6>&nbsp ;</div><a
href="http://ftp.netscape.co m/pub/netscape7/english/7.2/mac/Netscape-MachO.dmg.gz">M ac
OS X</a>');
document.write( "I've got a script that I'm trying to debug which uses
document.write( ) to place HTML within a page.");
document.write( '.vbmenu_hilite a:hover, .vbmenu_hilite a:active
{color: #FFFFFF; text-decoration: none;}');
document.write( 'alpha' , 'beta' , 'gamma');

//]]>
</script>
</head>
<body>
</body>
</html>

Works in IE, which allows a mimetype as an argument to
document.open() . Buggy in Firefox, no time to find out why. Should
allow you to at least see what's printing. I disagree about the 'one
big string' approach - document.write/ln take multiple arguments,
comma-separated as usual, an efficient way to avoid repeated
invocations.
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3889
by: Gregor Horvath | last post by:
Hi, Before I reinvent the wheel I`d like to ask if someone has done this before since I did not find an advice at Google. The goal is to create a dynamic Tree View in HTML. Say I have a data strucure like this: structList =
6
4983
by: Alan | last post by:
I'm just about to start a project that needs to combine the results of a SQL Server query with the results of an Index Server query. The basic idea is that the user enters/selects a bunch of search criteria on a form. Most of the criteria selected by the user will be used to select records from the database - standard WHERE clause stuff - but the user can also enter free-text that should be searched for in associated uploaded documents. The...
2
1840
by: relaxedrob | last post by:
Hi All! I have a frameset document and I want each mainFrame document to have the following ability: - be viewed by itself (i.e. without frames if within frameset). - be viewed within frame (i.e. put back in the frameset if not within frameset). I have written the following so far:
5
7408
by: Poster | last post by:
I have a script, its outputs are in HTML. It displays perferctly in a browser, however when I view source, it gives me the JS scripts, but I want to view the HTML output. Is there a way I can view or save output?
2
1699
by: Jack3000 | last post by:
Is there anyway to view what is written when using document.write? When I view the source from the webbrowser, I don't see the code that is written after the browser performs the document.write action. Many thanks!
1
1364
by: jloxsom | last post by:
Hi all... New user new to VC++. I've used the AppWizard to create an SDI with the CFormclass. The "View" file is a dialog. I want to create a few EditBoxes, associate member variables to them, and write them to a file (and retrieve them later). The "Doc" file contains the "serialize" function that looks perfect
2
1849
by: Justin | last post by:
I am creating a web app for a client in VS.NET using ASP.NET with C#. I need to query three tables in a database using one parameter and display the results on the page. my question is should I use a Stored Procedure or view in SQL Server to get the data from multiple tables? What is the difference? and where can I find a some articles on write code to display the results of the SP or view? Thanks, Justin.
1
1145
by: jagasker | last post by:
Hi, I am trying to write a javascript on Windows XP for my website that is supposed to perform a text search on an external page and return a result which, based on the result, will play a certain audio file. The script that I am writing is not working, I keep on getting redirected to the external page in which I am trying to perform the search, and I am getting numerous javascript errors, such as 'member not found', 'body is null or not an...
10
7365
by: Dutchmarshalls | last post by:
Hi All, I'm using a Pay Pal form script, but locally tested in Dreamweaver with a browser it will do exactly what I'm aspect it to do. Only when I'm uploaded the file on the server it will give this ERROR. By th way, I'm using a Joomla 1.5.3 site. The URL: http://www.dutchmarshalls.com/index.php/service/51-service/87-price-and-product-list- The ERROR CODE:...
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9336
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.