"View source" on webpage?

  • CaspianXI
  • Born
  • Born
  • CaspianXI
  • Posts: 2

Post 3+ Months Ago

I'm trying to create a script that will allow my visitors to click a "view source" button on my page. This button will cause a textarea to be filled with the source of the present page. (The source of the page is dynamic)

Does anyone know how I can do this? (using Javascript, ActiveX, or something web-based) Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

You can get the source between the body tags to show up like this.

Code: [ Select ]
<html>
<head>
<script language="javascript">
    function viewS(){
        out.value = document.body.outerHTML;
    }
</script>

</head>
<body>

<textarea id="out" cols="50" rows="5"></textarea>

<input type="button" onClick="viewS()" value="View Source">

</body>
</html>
  1. <html>
  2. <head>
  3. <script language="javascript">
  4.     function viewS(){
  5.         out.value = document.body.outerHTML;
  6.     }
  7. </script>
  8. </head>
  9. <body>
  10. <textarea id="out" cols="50" rows="5"></textarea>
  11. <input type="button" onClick="viewS()" value="View Source">
  12. </body>
  13. </html>


Internet Explorer, and foxfire support the "view-source" protocall.

Use this link to have googles source popup in notepad.
view-source:http://www.google.com
  • rjmthezonenet
  • Expert
  • Expert
  • User avatar
  • Posts: 526
  • Loc: St. John's, Newfoundland, Canada

Post 3+ Months Ago

Mozilla/Netscape also support view-source:http://...
  • CaspianXI
  • Born
  • Born
  • CaspianXI
  • Posts: 2

Post 3+ Months Ago

Wow! Thanks. That's a big help to me. :):D
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

rjmthezonenet wrote:
Mozilla/Netscape also support view-source:http://...


Thats good to know. I wasn't sure if they did & diddn't feel like checking so I kept it to what I know. :wink:
  • rjmthezonenet
  • Expert
  • Expert
  • User avatar
  • Posts: 526
  • Loc: St. John's, Newfoundland, Canada

Post 3+ Months Ago

joebert wrote:
Thats good to know. I wasn't sure if they did & diddn't feel like checking so I kept it to what I know.


I just happened to be using Mozilla at the time I was reading your post. Where did you come across view-source:http:// ? I searched everywhere...
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

heres where i found it
http://www.ideaspace.net/users/wkearney/archives/entries/000460.html
  • LazyJim
  • Student
  • Student
  • LazyJim
  • Posts: 92

Post 3+ Months Ago

Code: [ Select ]
var sSource = "<html>" + document.getElementsByTagName('HTML')[0].innerHTML + "</html>";
alert(sSource);
  1. var sSource = "<html>" + document.getElementsByTagName('HTML')[0].innerHTML + "</html>";
  2. alert(sSource);


<a href="javascript: alert('<html>' + document.getElementsByTagName('HTML')[0].innerHTML + '</html>')">test it by clicking here</a>
  • Ruroni_soujiro
  • Born
  • Born
  • Ruroni_soujiro
  • Posts: 1

Post 3+ Months Ago

I have 3 frames One is navigation frame, then there is another frame (called source) where I have a <textarea> and then I have content frame.

The navigation frame has a function
Code: [ Select ]
function displayCode()
{
var sSource = "<html>" + parent.Content.document.getElementsByTagName('HTML')[0].innerHTML + "</html>";
parent.source.sourceCode.value = sSource;
}
  1. function displayCode()
  2. {
  3. var sSource = "<html>" + parent.Content.document.getElementsByTagName('HTML')[0].innerHTML + "</html>";
  4. parent.source.sourceCode.value = sSource;
  5. }

which can write the source code of the content frame into the <TEXTAREA> of the left column frame (source). This works wonderfully when loading the DEFAULT content Place holder I made, but if the content frame loads another page, the source code button doesn't work anymore.

So: parent.Content.document.body.outerHTML gets me the source code for Content; the question is how can I make it to where "Content" can be any page I visit? (I tried inserting Google in place of Content, (parent.Google.document.body.outerHTML Since Google is Google's title) and visited content in the display Pane, that didn't work)

I figured maybe somehow getURL (or some kind of function or some trick that could be used across platforms ) into a variable on the navigation? But how to get it form the "Content" frame, into the navigation frame, is guess would be my troubles?

Anyone, help?

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 143 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.