howtos » Triggering the Source Code view of the current page using JavaScript
Triggering the Source Code view of the current page using JavaScript
I was recently writing a demo to showcase the new Google Language API, and in my demo I did the usual thing of instructing users to View > Page Source in order to view the source code and comments. I know this is less than ideal, because it forces users to have to process the instructions, and then execute them. Somewhere in there you lose them and they never execute the desired action.
It got me thinking: is there a way to have the source code in front of them in one click? A few Google searches later, and the answer was yes!
Using JavaScript you can open a new window to display the source code view of the current window:
JAVASCRIPT:
-
window.open('view-source:' + window.location.href, 'mysource');
Voila! How easy was that? Now it's your turn.
Leave a comment