IT.COM

JavaScript: Allow your visitors to View the Source Code of Web Pages from your site

Spaceship
Watch
Impact
6
This code allows your visitors to type any url in a text box and will attempt to retrieve the source code. View example: http://www.webdesigntalk.net/tools/viewsource.html

Add this to the head section of your page:
Code:
<script language="JavaScript" type="text/javascript">
<!-- Code by deadserious - http://www.webdesigntalk.net -->

function http(){
    if (document.getsource.view.defaultvalue != document.getsource.view.value)
    {document.getsource.view.value = "View Source"}
    if (document.getsource.url.defaultvalue != document.getsource.url.value)
    {document.getsource.url.value = "http://"}
}
function viewSource(){
    document.getsource.view.value="One Moment Please"; 
    var geturl = document.getsource.url.value; {
    var SourceUrl = "view-source:" + geturl ; location.href = SourceUrl;
    }
}

</script>
Add this to the body section of your page:
Code:
    <form name="getsource" action="">
      <b>URL:</b> <input type="text" name="url" onfocus="http()"
      value="http://" /> <input type="button" name="view"
      value="View Source" onclick="viewSource()" />
    </form>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Whoa that's cool! Thanks for posting it deadserious!
 
0
•••
Nice script.

but who is gonna use it?
 
0
•••
I used it on my new website. Except I modified it to:

<A HREF="javascript:window.location.replace('view-source:' + window.location + '');">view my source</A>

Very usefull.
 
0
•••
Originally posted by Daniel Smith
Nice script.

but who is gonna use it?

people who are trying to see the source but are being barraged by right click protection popups?
 
0
•••
I could def. use that. I didn't know that was possible!

Thanks!
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back