html - Displaying Source Of Javascript Code -
i accomplish like:
<html> <head> <script id="viewsource" src="somejsfile.js"/> <script language="javascript"> function view() { var el=document.getelementbyid("viewsource"); //works var ta=document.getelementbyid("ta"); //works ta.value=el.innerhtml; //doesn't work } </script> </head> <body> <textarea id="ta"/> <a href="javascript:view();">view javascript source code</a> </body> </html> // (please pardon typos/errors, above illustrate mean)
of course "innerhtml" doesn't work on script tags. property/attribute can access view source?
i realize can accomplished clicking view source in browser. crazy hope can done javascript?
thanks in advance.
why don't fire ajax call , download "somejsfile.js"? once downloaded have access in js variable.
if using jquery can done using $.get
: http://api.jquery.com/jquery.get/
edit: in theory shouldn't re-download file since cached in browser (depends on server settings , browser settings).
- christian
Comments
Post a Comment