view source

S

shr

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
 
M

Martin Honnen

shr said:
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.

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.
 
E

Evertjan.

shr wrote on 29 sep 2004 in comp.lang.javascript:
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.

<http://groups.google.com/groups?th=693cf051b8e70a91>

for IE, because that was on a jscript group.
 
I

Ivo

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.

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

javascript:'<code><ol><li>'+(document.documentElement||document.body).outerH
TML.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/ /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 >
 
T

Thomas 'PointedEars' Lahn

Martin said:
shr said:
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.

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.

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
 
T

Thomas 'PointedEars' Lahn

Thomas said:
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.

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
 
R

Randy Webb

Thomas said:
Thomas 'PointedEars' Lahn wrote:




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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top