Click to See Complete Forum and Search --> : View source code in browser window?


airski
10-17-2003, 11:49 AM
I know how to use javascript to view the source code of a webpage:

<script language=JavaScript>
function ViewSource() {
window.location = "view-source:" + window.location.href }
</script>

<a href=javascript:ViewSource() class="body">Get Code</a>

The only problem is that this opens in a notepad or another editor. How can i do the same thing, but make it open in a new broswer window?

thanks

Khalid Ali
10-18-2003, 07:36 AM
You can not make any changes to this behavior.
IE by default opens up source code of a pag in notepad.( or possibley any default text editor ona machine),If you don't like this behavior use Netscape browsers they open source in the same browser window as you want.

AdamGundry
10-18-2003, 02:39 PM
You can use Javascript to get the contents of the <body> tag, using document.body.innerHTML, which might help depending on what you want to do. Something like this (uses regular expressions to convert < and > to HTML entities:

<script type="text/javascript">
w = window.open('about:blank');
w.document.write(document.body.innerHTML.replace(/</, '&lt;').replace(/>/, '&gt;'));
</script>

Adam