view source

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

    view source

    Is there any way by which I can display the source of a html page
    using the 'view:source' command, in an iframe??
    I tried using this
    viewer.location = "view-source:" + viewer.location .href;
    where viewer is an iframe.
    but it opens the source in a notepad.

    Instead of the source getting displayed in the notepad, I would like
    the iframe to display the source.

    Thanks in advance
  • Martin Honnen

    #2
    Re: view source



    shr wrote:
    [color=blue]
    > Is there any way by which I can display the source of a html page
    > using the 'view:source' command, in an iframe??
    > I tried using this
    > viewer.location = "view-source:" + viewer.location .href;
    > where viewer is an iframe.
    > but it opens the source in a notepad.
    >
    > Instead of the source getting displayed in the notepad, I would like
    > the iframe to display the source.[/color]

    You could use server-side scripting to serve the page with the HTTP header
    Content-Type: text/plain
    instead of the associatd text/html but IE is known to try to sniff the
    content and ignore that. Client-side script is not going to help, at
    least not across browsers.

    --

    Martin Honnen

    Comment

    • Evertjan.

      #3
      Re: view source

      shr wrote on 29 sep 2004 in comp.lang.javas cript:
      [color=blue]
      > Is there any way by which I can display the source of a html page
      > using the 'view:source' command, in an iframe??
      > I tried using this
      > viewer.location = "view-source:" + viewer.location .href;
      > where viewer is an iframe.
      > but it opens the source in a notepad.
      >
      > Instead of the source getting displayed in the notepad, I would like
      > the iframe to display the source.
      >[/color]

      <http://groups.google.c om/groups?th=693cf 051b8e70a91>

      for IE, because that was on a jscript group.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress,
      but let us keep the discussions in the newsgroup)

      Comment

      • Ivo

        #4
        Re: view source

        "Martin Honnen" wrote[color=blue]
        > shr wrote:[color=green]
        > > Instead of the source getting displayed in the notepad, I would like
        > > the iframe to display the source.[/color]
        >
        > You could use server-side scripting to serve the page with the HTTP header
        > Content-Type: text/plain
        > instead of the associatd text/html but IE is known to try to sniff the
        > content and ignore that. Client-side script is not going to help, at
        > least not across browsers.[/color]

        This bookmarklet writes the generated source in the page, you could turn it
        into a regular function:

        javascript:'<co de><ol><li>'+(d ocument.documen tElement||docum ent.body).outer H
        TML.replace(/&/g,"&amp;").repl ace(/</g,"&lt;").repla ce(/ /g,"&nbsp;
        ").replace(/\n/g,"<li>")+'<\/ol><\/code>';

        The the downloaded source and the generated source may differ significantly.
        You can get the first one in a variable with the XML HTTP Request object.
        See
        <URL: http://jibbering.com/2002/4/httprequest.html >
        --
        Ivo


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: view source

          Martin Honnen wrote:
          [color=blue]
          > shr wrote:[color=green]
          >> Is there any way by which I can display the source of a html page
          >> using the 'view:source' command, in an iframe??
          >> [...]
          >> Instead of the source getting displayed in the notepad, I would like
          >> the iframe to display the source.[/color]
          >
          > You could use server-side scripting to serve the page with the HTTP header
          > Content-Type: text/plain
          > instead of the associatd text/html but IE is known to try to sniff the
          > content and ignore that. Client-side script is not going to help, at
          > least not across browsers.[/color]

          However, if server-side scripting is available, ways are available
          to convert "<" to "&lt;" and ">" to "&gt;". Not even IE will try
          to parse the content then. The document must be served as text/html
          (or application/xhtml+xml) with a surrounding "body" element, though.
          The "pre" element should come in handy then.


          PointedEars
          --
          If there were no BUGs........... .we wouldn't have our jobs!

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: view source

            Thomas 'PointedEars' Lahn wrote:
            [color=blue]
            > However, if server-side scripting is available, ways are available
            > to convert "<" to "&lt;" and ">" to "&gt;". Not even IE will try
            > to parse the content then. The document must be served as text/html
            > (or application/xhtml+xml) with a surrounding "body" element, though.
            > The "pre" element should come in handy then.[/color]

            Or, much more simple, if server-side PHP is available and the file is
            on an ext2 compatible filesystem, one could place a symlink with the
            suffix .phps to point to the .html file (if the filesystem is not
            ext2 compatible, a renamed copy of the .html file is required). PHP
            will then output the color-coded source code if used as an Apache
            module, the Apache configuration contains

            AddType application/x-httpd-php-source .phps

            and the .phps file is accessed as HTTP resource. Example:

            <http://www.pointedears .de/scripts/test/dom.xhtml.phps>


            PointedEars
            --
            "I have the heart of a small boy -- and I keep it in a jar on my desk."

            Comment

            • Randy Webb

              #7
              Re: view source

              Thomas 'PointedEars' Lahn wrote:[color=blue]
              > Thomas 'PointedEars' Lahn wrote:
              >
              >[color=green]
              >>However, if server-side scripting is available, ways are available
              >>to convert "<" to "&lt;" and ">" to "&gt;". Not even IE will try
              >>to parse the content then. The document must be served as text/html
              >>(or application/xhtml+xml) with a surrounding "body" element, though.
              >>The "pre" element should come in handy then.[/color]
              >
              >
              > Or, much more simple, if server-side PHP is available and the file is
              > on an ext2 compatible filesystem, one could place a symlink with the
              > suffix .phps to point to the .html file (if the filesystem is not
              > ext2 compatible, a renamed copy of the .html file is required). PHP
              > will then output the color-coded source code if used as an Apache
              > module, the Apache configuration contains
              >
              > AddType application/x-httpd-php-source .phps[/color]

              Since you bring it up, that extension can be just about anything you
              want it to be, including - but not limited to - phps. Personally, I use
              the extension .source instead of phps which can be misleading.


              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq

              Comment

              Working...