<xmp> with innerHTML to display source code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ddailey

    <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><st yle>
    #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.docume ntElement.inner HTML

    function display(L){
    L.innerHTML+="< code>"+a+"<\/code>"
    }
    </script></head>
    <body onload="display (document.getEl ementById('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>
  • =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?=

    #2
    Re: &lt;xmp&gt; with innerHTML to display source code

    ddailey <ddailey@zoomin ternet.netwrote :

    ....

    I'm using :
    <html><head><sc ript>
    window.onload=f unction(){
    document.getEle mentById('sourc e').appendChild (
    document.create TextNode(
    document.getEle mentsByTagName( '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

    Comment

    • Lee

      #3
      Re: &lt;xmp&gt; with innerHTML to display source code

      On Jun 3, 12:03 am, unbewusst.s...@ weltanschauung. com.invalid (Une
      Bévue) wrote:
      ddailey <ddai...@zoomin ternet.netwrote :
      >
      ...
      >
      I'm using :
      <html><head><sc ript>
      window.onload=f unction(){
        document.getEle mentById('sourc e').appendChild (
          document.create TextNode(
            document.getEle mentsByTagName( '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.

      Comment

      • Lee

        #4
        Re: &lt;xmp&gt; with innerHTML to display source code

        On Jun 3, 12:03 am, unbewusst.s...@ weltanschauung. com.invalid (Une
        Bévue) wrote:
        ddailey <ddai...@zoomin ternet.netwrote :
        >
        ...
        >
        I'm using :
        <html><head><sc ript>
        window.onload=f unction(){
          document.getEle mentById('sourc e').appendChild (
            document.create TextNode(
              document.getEle mentsByTagName( '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.

        Comment

        Working...