View page source with a link or a button using Java Script
In Category JavaScript
window.location can be set to a special location using view-source: followed by window.location.href to make browser to display source code of the current page. This can be attached to a standard link or a click of a button as shown below.
The following shows how to fire view-source window using a standard link:
Place this code between <head> and </head> tags of the page.
<script language=JavaScript>
function viewSource() {
window.location = "view-source:" + window.location.href;
}
</script>
Place this code where you would like your link to appear.
<a href="javascript:viewSource()">View Source</a>
Alternately if button needs to fire the view-source window of the browser, add the following piece of code to the page.
<form> <input type="button" value="View Source" onClick= 'window.location = "view-source:" + window.location.href' > </form>
Recent Comments