473,505 Members | 16,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<xmp> with innerHTML to display source code

The code which follows is something I cobbled together quite hastily
to display to students a way of illustrating HTML source code
(including CSS and JavaScript) alongside a page as rendered. I've done
this a dozen different ways for slightly different purposes and rather
can't remember what the various outcomes of my inquiries have been.

In the following I use <xmpas a way of displaying source code. It
works in IE, Opera, and FF, but I recall hearing that <xmpis to be
deprecated and that it provides no functionality that cannot otherwise
be performed without it. Whence the question: how does one do the
following without <xmp>? [aa identical approach using <codeseems to
do utterly zilch]

thanks in advance
dpd

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><style>
#left{
position: absolute;
top: 0;
left: 0;
width: 55%;
background: #fe8;
color: #018;
}
#right{
position: absolute;
top: 0;
left: 55%;
}
..text{
margin: 15px;
}
</style>
<script>
var a = document.documentElement.innerHTML

function display(L){
L.innerHTML+="<code>"+a+"<\/code>"
}
</script></head>
<body onload="display(document.getElementById('left'))">
<div id="left">
<div class="text">
<b>Here, in the div with id="left", we see the mechanics of the page.</
b>
</div>
</div>
<div id="right">
<div class="text">
<h2>Two column layout using CSS</h2>
<p>Here in the div with id="right", is where ordinary web stuff goes.</
p>
</div>
</div>

</body>
</html>
Jun 27 '08 #1
3 2624
ddailey <dd*****@zoominternet.netwrote:

....

I'm using :
<html><head><script>
window.onload=function(){
document.getElementById('source').appendChild(
document.createTextNode(
document.getElementsByTagName('script')[0].text));
}
</script></head>
<body>
<dl>
<dt>Source code:</dt>
<dd>
<pre id="source"/>
</dd>
</dl>
</body></html>

tested on Mac OS X with Firefox, Opera and Safari.

--
Une Bévue
Jun 27 '08 #2
Lee
On Jun 3, 12:03*am, unbewusst.s...@weltanschauung.com.invalid (Une
Bévue) wrote:
ddailey <ddai...@zoominternet.netwrote:

...

I'm using :
<html><head><script>
window.onload=function(){
* document.getElementById('source').appendChild(
* * document.createTextNode(
* * * document.getElementsByTagName('script')[0].text));}

</script></head>
<body>
* <dl>
* * <dt>Source code:</dt>
* * <dd>
* * * <pre id="source"/>
* * </dd>
* </dl>
</body></html>

tested on Mac OS X with Firefox, Opera and Safari.

--
Une Bévue
Try textarea instead of the code tags.
Jun 27 '08 #3
Lee
On Jun 3, 12:03*am, unbewusst.s...@weltanschauung.com.invalid (Une
Bévue) wrote:
ddailey <ddai...@zoominternet.netwrote:

...

I'm using :
<html><head><script>
window.onload=function(){
* document.getElementById('source').appendChild(
* * document.createTextNode(
* * * document.getElementsByTagName('script')[0].text));}

</script></head>
<body>
* <dl>
* * <dt>Source code:</dt>
* * <dd>
* * * <pre id="source"/>
* * </dd>
* </dl>
</body></html>

tested on Mac OS X with Firefox, Opera and Safari.

--
Une Bévue
Try the textarea tag instead of the code tag.
Jun 27 '08 #4

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

Similar topics

8
13425
by: Martin Ernst | last post by:
Hello. I want to show HTML source code in my browser (for debugging purposes). Which tag/formatting di i have to use to tell the browser not to render the code but display it as pure text? ...
22
3031
by: Brent | last post by:
I want to paste a lengthly text document into a web page and have it retain all of whitespace and line breaks. I first tried the <pretag but that didn't work because it doesn't wrap the text. I...
1
1848
by: programmerboy | last post by:
I am trying to write html tags using <xmp> tag. However, it writes everything in one line only. Is there a way we can format it to look prettier (like an xml document)?
10
3126
by: Remus | last post by:
Greetings, My first time on this forum. I hope someone can help me out. I am trying to get 11 values from several different identically structured webpages. I have the list of webpages saved as...
0
7218
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,...
0
7307
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
7478
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...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
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...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
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 ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
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...

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.