1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to show HTML code on a web page?

Discussion in 'HTML & Website Design' started by MattUK, Nov 1, 2005.

Thread Status:
Not open for further replies.
  1. #1
    This is probably very simple, but I'd like to show some HTML code on a web page. Are there any tags that I can use that will prevent the code being executed and will just show the raw code on the page. I'm having real trouble finding out how to do this.
     
    MattUK, Nov 1, 2005 IP
    Briant likes this.
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to encode HTML; that is, < will be converted to &lt; etc. There are special functions that do this encoding. For example, in ASP you would use Server.HTMLEncode. In PHP you could use htmlspecialchars or htmlentities.

    J.D.
     
    J.D., Nov 1, 2005 IP
  3. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Use the following character conversions:
    http://ascii.cl/htmlcodes.htm

    A far better way would be to use your scripting language's equivalent of the VBScript Server.HTMLEncode().

    Also, pasting HTML in to a WYSIWYG editor will typically sort all the conversions out for you.

    - Jamie
     
    JamieC, Nov 1, 2005 IP
  4. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #4
    Right, this is just getting scary...
     
    JamieC, Nov 1, 2005 IP
  5. MattUK

    MattUK Notable Member

    Messages:
    6,950
    Likes Received:
    377
    Best Answers:
    0
    Trophy Points:
    275
    #5
    I've tried that with DW but it seems to convert it
     
    MattUK, Nov 1, 2005 IP
  6. JamieC

    JamieC Well-Known Member

    Messages:
    226
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    138
    #6
    I gave up on Dreamweaver a while ago, but you should first ensure that you are in design view rather than code view.

    There may be an option in the preferences somewhere to enable / disable code conversion - check for it.

    Paste the code into notepad and recopy, just to ensure you don't have any weird OLE objects in your clipboard or something.
     
    JamieC, Nov 1, 2005 IP
  7. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Enclose the html code between xmp tags, for example:

    <xmp>insert code here</xmp>
     
    dave487, Nov 2, 2005 IP
  8. wrmineo

    wrmineo Peon

    Messages:
    3,087
    Likes Received:
    379
    Best Answers:
    0
    Trophy Points:
    0
    #8
    In DW, you create a "form" element and then input a "text" area and the code will be put on the page as text without being rendered or executed.

    Here's a working example:
    http://www.freshdames.com/banners.html

    <form name="form1" method="post" action="">
      <textarea name="textarea" cols="72" rows="10"><!--======================== BEGIN COPYING THE HTML HERE ==========================-->
    <img name="celebrity_pics2" src="http://www.freshdames.com/babes/banners/celebrity_pics2.gif" width="640" height="90" border="0" usemap="#m_celebrity_pics2" alt=""><map name="m_celebrity_pics2">
    <area shape="rect" coords="560,0,640,90" href="http://www.freshdames.com/swank/index.html" target="_blank" title="Hilary Swank pictures, films, biography and more Oscar winning Best Actress Hilary Swank!" alt="Hilary Swank pictures, films, biography and more Oscar winning Best Actress Hilary Swank!" >
    <area shape="rect" coords="480,0,560,90" href="http://www.freshdames.com/trachtenberg/gallery1/index.htm" target="_blank" title="Michelle Trachtenberg pictures!" alt="Michelle Trachtenberg pictures!" >
    <area shape="rect" coords="400,0,480,90" href="http://www.freshdames.com/kournikova/wallpapers/index.htm" target="_blank" title="Anna Kournikova pictures and wallpapers." alt="Anna Kournikova pictures and wallpapers." >
    <area shape="rect" coords="320,0,400,90" href="http://www.freshdames.com/paris-hilton.html" target="_blank" title="Paris Hilton pictures" alt="Paris Hilton pictures" >
    <area shape="rect" coords="160,0,240,90" href="http://www.freshdames.com/jessica_simpson.html" target="_blank" title="Jessica Simpson Pictures, Wallpapers and related information." alt="Jessica Simpson Pictures, Wallpapers and related information." >
    <area shape="rect" coords="241,0,320,90" href="http://www.freshdames.com/mandy_moore/index.html" target="_blank" title="Mandy Moore pictures, news, and more Mandy Moore at FreshDames" alt="Mandy Moore pictures, news, and more Mandy Moore at FreshDames" >
    <area shape="rect" coords="80,0,160,90" href="http://www.freshdames.com/HotKnowles.html" target="_blank" title="Beyonce Knowles hot pictures, wallpapers, biography, music and more Beyonce Knowles." alt="Beyonce Knowles hot pictures, wallpapers, biography, music and more Beyonce Knowles." >
    <area shape="rect" coords="0,0,80,90" href="http://www.freshdames.com/EvaLongoria/index.html" target="_blank" title="Desperate House Wife Eva Longoria pictures, news, and links at Fresh Dames!" alt="Desperate House Wife Eva Longoria pictures, news, and links at Fresh Dames!" >
    </map>
    <!--========================= STOP COPYING THE HTML HERE =========================-->
      </textarea>
      <a href="http://www.freshdames.com/babes/banners/celebrity_pics2.html" title="Example" target="_blank">Fresh
      Dames Banner</a>
    </form>
    Code (markup):
     
    wrmineo, Nov 2, 2005 IP
  9. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #9
    Use Frontpage. You just treat it like normal text with it.
     
    mcfox, Nov 2, 2005 IP
  10. zhisede

    zhisede Peon

    Messages:
    103
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    In Dreamweaver and Frontpage, you can just type in anything you want and the software will change it automatically. If you need to get input from a form using server side scripts like PHP, a function will convert all the input.
     
    zhisede, Nov 3, 2005 IP
  11. dtang4

    dtang4 Active Member

    Messages:
    303
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #11
    You have a few options:
    - enclose the code in <pre> </pre>
    - enclose the code in <xmp> </xmp> - I think this is the preferred method
    - enclose the code in <textarea> </textarea> - just put it in a form textarea box
     
    dtang4, Nov 3, 2005 IP
  12. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #12
    I just put the code in a textarea.
     
    bschneider5, Nov 4, 2005 IP
  13. minstrel

    minstrel Illustrious Member

    Messages:
    15,082
    Likes Received:
    1,243
    Best Answers:
    0
    Trophy Points:
    480
    #13
    I've never actually tried to do this but this is from WebDesignGroup's help file:

     
    minstrel, Nov 4, 2005 IP
  14. m1t0s1s

    m1t0s1s Peon

    Messages:
    125
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Use a wysiwyg editor like the free/open-source Mozilla NVU. Copy and paste, it does it all for you.

    Sorry about bumping an old thread, but I hate frontpage that much. :mad:

    If you're into manually converting or a quick lookup, type firefox's "wp [character]" into the address bar, and search for html. It will show you the correct html entity.

    like:
    wp "
    Code (markup):
     
    m1t0s1s, Jul 1, 2007 IP
  15. baybossplaya

    baybossplaya Active Member

    Messages:
    597
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #15
    was having trouble doing this and found this in the search
     
    baybossplaya, May 2, 2008 IP
  16. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #16
    Never us xmp. Its not HTML, and I highly doubt it will work in anything other than IE or Fx. A very bad, and very stupid thing to do.

    To do it follow these steps:

    1. Replace < with &lt;

    2. Replace > with &gt;
     
    blueparukia, May 2, 2008 IP
  17. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #17
    ^ take that excellent advice, and then know that both <code> and <pre> will also get the job done (and because of some browser, hmmm, who could that be? can't handle them seperately, you should put <pre> and <code> together).

    xmp never quite properly conformed to SGML apparently. Hell, I'd never heard of it before someone mentioned it on another thread on the forums, it's so outdated.
     
    Stomme poes, May 3, 2008 IP
  18. Yankee85

    Yankee85 Peon

    Messages:
    1,067
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #18
    You can use the <pre> tag as Stomme poes said.
     
    Yankee85, May 3, 2008 IP
  19. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #19
    But, not by itself. Also, IE can consider everything inside pre to be a single, long line, so often you need to tell IE word-wrap: break-word to keep it in line.

    
    <pre>
      <code> stuff stuff stuff stuff</code>
    </pre>
    
    Code (markup):
    Then you would style pre in CSS and let code alone to do its thing. You still use &lt and &gt for brackets, but all indenting, whitespace and newlines are preserved.
     
    Stomme poes, May 3, 2008 IP
  20. bjplink

    bjplink Peon

    Messages:
    243
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #20
    bjplink, May 6, 2008 IP
Thread Status:
Not open for further replies.