We help IT Professionals succeed at work.

link to show html source

tmonteit
tmonteit asked
on
How to I build a link that shows my html source and not have it rendered by the browser?

Just to show it as a block of text...
Comment
Watch Question

Top Expert 2013
Commented:
Just make a copy of the file and save it with a .txt extension then it is just and ordinary link:

a href="yourpage.txt"> get source code</a>

Open in new window



Cd&

Commented:
http://support.microsoft.com/kb/188762
I'm not sure it will work on all browsers
Top Expert 2013

Commented:
OH.  I had forgotten about that old protocol.  It is so easy not to get source, that nobody even uses it any more, There is no reason it should not work in every browser and in fact if I recall correctly you can even use it in the address bar.

Cd&

Commented:
that won't work on all browsers... for example, safari on a mac cannot resolve it
firefox needs something else
i guess it was to use a javascript like

<a href="javascript:view-source:" + location.href + "; void(0);">

but it won't work in most of the browsers

maybe on internet explores, since that browser is full of errors so it doesn't matter if your html page is as well...
Top Expert 2013

Commented:
It works fine i FF but the urlhas to be fully qualified, however as with anything it might run into security issues cross domain.


Cd&
Top Expert 2011

Commented:
Are you interested in displaying the source file in HTML, like in a code block?

Your source file goes here

Open in new window


Or purely, you want the user to be able to click a link that lets them view the page's source code (like, the raw PHP or ASP code)?