Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Stop browser reading tags?

  1. #1
    Join Date
    Sep 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Stop browser reading tags?

    Hi how do you stop the browser reading tags?

    ie if I wanted to write a tutorial on HTML I'd need to be able to tell people to write:

    <p>Duck</p>

    and not have it appear as Duck (ie have the <p> tags interpreted)

    I've tried blockquote and pre tags, but no joy...

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Replace "<" with "&lt;" and replace ">" with "&gt;"
    - Mike

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    mburt is right, that is the correct way to do this but, sometimes that can get to be a bit tedious. I think this is invalid but, it works in most modern browsers:

    HTML Code:
    <textarea cols="30" rows="5" style="border-width:0;font-family:sans-serif;">
    <p>Duck</p>
    </textarea>
    If you allow enough rows and cols for the displayed content there should be no scrollbars and it will look like ordinary text - useful if you have a lot of content of this nature to display.

    Or, you can just skip the style and have a textarea for your users to easily know they can select and copy from it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Better:
    Code:
    <![CDATA[
      <p>Duck</p>
    ]]>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    It would be wise to add 'readonly' to the textarea tag. You could make it like a normal div with some style:
    Code:
    <textarea readonly style="height:300px;width:500px;border:0px;overflow:hidden;font:12px arial"><p>The tags will appear here</p></textarea>
    - Mike

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'm not sure if that boolean shorthand is valid HTML Strict or not, but it's certainly not valid XHTML. For maximum portability, readonly="readonly" is preferable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey
    I'm not sure if that boolean shorthand is valid HTML Strict or not, but it's certainly not valid XHTML. For maximum portability, readonly="readonly" is preferable.
    For HTML, readonly="readonly" is invalid. Or, at the very east, what you call shorthand is the preferred method. And, why worry about portability? Aren't you one of the ones going around telling people not to write XHTML unless it is XHTML?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    I think this is invalid but, it works in most modern browsers:
    HTML Code:
    <textarea cols="30" rows="5" style="border-width:0;font-family:sans-serif;">
    <p>Duck</p>
    </textarea>
    Yes, it is.

    To avoid the tediousness, one could just use a region-limited search and replace operation. Any good text editor should be capable of it.


    Quote Originally Posted by Twey
    Better:

    Code:
    <![CDATA[ <p>Duck</p> ]]>
    In theory, but not in practice unless one is serving an application of SGML or XML to be processed as SGML or XML (for which neither HTML nor XHTML as HTML qualifies).

    I'm not sure if that boolean shorthand is valid HTML Strict or not
    The document type doesn't matter, and it is valid.

    For maximum portability, readonly="readonly" is preferable.
    The recommendation has been to the contrary, though it may not be quite as significant as it once was.


    Quote Originally Posted by jscheuer1
    For HTML, readonly="readonly" is invalid.
    Not at all. The readonly attribute has only one value: readonly.

    See towards the end of section 3.3.4 Attribute declarations and appendix B.3.4 Boolean attributes for more information on boolean attributes.

    Mike

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by jscheuer1
    And, why worry about portability? Aren't you one of the ones going around telling people not to write XHTML unless it is XHTML?
    That doesn't mean that it's wrong to use something that's valid in XHTML if it's also valid HTML While there's no downside, there's no real reason not to do so.
    Quote Originally Posted by mwinter
    The recommendation has been to the contrary
    Why so?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Another simple answer... if you're using dreamweaver or any other html wysiwyg editor, just copy and paste the code into the preview view.
    That will automatically convert for you.
    Then go to the code, and cut/paste that, and it will have the &gt; and &lt; tags all done for you.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •