Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    GDS
    GDS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Access to source code?

    Is it possible, by scripting, to get access to the complete source code of a document, as you see it if you right-click on a page?

    (That is, the original source before any scripting etc. has occured.)


    GDS

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Reading http requests thru browsers/scripting?

    You may or may not be able to use your browser to do this. Netscape 4.x shows you all dynamically written html as plain html, mozilla/ie shows you the scripting but not the resultant html (only the formatted stuff in the browser window - you can see it graphically).

    Data going over HTTP is unencrypted - it's plain text so any program that can allow you to view textual http requests will work. There are hundreds out there - cURL (http://curl.sourceforge.net/) netcat (http://www.atstake.com/research/tools/) are just two of many that are fairly easy to use. - I just give both of these a thumbs up because of their usefulness for information finding - you can use an activeX script to initiate these programs, then read out the content of the resultant file.

    You could write a bit of client-side FSO(FileSystemObject) to download the page from the server into an iframe, then drop the html from your browser cache folder as text onto the page.

    Hope this helps and didn;t get too bogged down and unreadable, I would imagine/hope someone out in the ether has a better way than any I've mentioned, it's an interesting question

    m_n
    Last edited by martin_narg; 08-23-2002 at 01:39 PM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    GDS
    GDS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    tanks for your reply, martin_narg.

    martin_narg wrote:
    * Reading http requests thru browsers/scripting?

    Well, not exactly, I "only" want to load the original html-text
    for a given frame into a javascript variable.
    It already is there, but I don't know how to get hold of it.


    martin-narg wrote:
    * you can use an activeX script to initiate these programs,
    * then read out the content of the resultant file.

    This solutions seems to be a little bit complex.
    It reqires downloading a program, and I really don't know
    how to use activeX.

    martin-narg wrote:
    * You could write a bit of client-side FSO(FileSystemObject) to
    * download the page from the server into an iframe, then drop
    * the html from your browser cache folder as text onto the page.

    The use of FSO certainly will solve the problem, but I feel this
    as a over-kill as long as the HTML-text already is there.

    The reason I asked this question is that I am makeing a simple
    HTML editor in javascript. It works fine, but if the content is
    changed during loading, then I no longer have a unmodified
    source to work on.

    One solution would be to turn off scripting completely
    for one frame only, but I think that is not possible?


    GDS

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    You can retrieve the dynamic page source as a string:

    IE:

    document.documentElement.outerHTML;

    Moz:

    (new XMLSerializer()).serializeToString(document)

  • #5
    GDS
    GDS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    jdk wrote:

    * You can retrieve the dynamic page source as a string:
    * IE:
    * document.documentElement.outerHTML;


    Your solution will not do the job for me,
    as this is the dynamically changed source.
    Consider this code:


    <html>
    <head>
    <title>get source</title>

    <script>
    function getSource(){
    var S=document.documentElement.outerHTML;
    alert(S)
    }
    </script>

    </head>
    <body>
    <button onclick="getSource()">get Source</button>

    <script>
    document.write("This stuff is <i>scripted</i> into the document!")
    </script>

    </body>
    </html>


    If you hit the button, you will get some kind of reformatted code, as it looks after the document.write has done the job.

    There is also some minor changes, the small letters in html tags is changed to big letters and whitespace is not the same.

    (I have not tested the Moz version yet.)


    GDS

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What you want is:

    javascript:(function(){%20function%20htmlEscape(s){s=s.replace(/&/g,'&amp;');s=s.replace(/>/g,'&gt;');s=s.replace(/</g,'&lt;');return%20s;}%20x=window.open();%20x.document.write('<pre>'%20+%20htmlEscape('<html>\n'%20+ %20document.documentElement.innerHTML%20+%20'\n</html>'));%20x.document.close();%20})();

    Remove the space between javascript: and (function. I only did this because it causes a frown to occur when posting.

    <edit my="post" />
    Fixed a frown bug described in the above paragraph.
    Last edited by boxer_1; 08-24-2002 at 11:25 PM.

  • #7
    GDS
    GDS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    jscript_junkie:

    The probem is that I don't have access to the untampered source code, as you see it when you select View source from the menu.

    If you try my script posted earlier, you will see that the
    alert also includes the text scripted by the document.write().

    GDS

  • #8
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    hmm, try this?

    Code:
    <html>
    <head>
    <title>view source</title>
    <script language=JavaScript>
    function ViewSource() {
    window.location = "view-source:" + document.location.href }
    </script>
    
    </head>
    <body bgcolor="white">
    <form name="myForm">
    <input type="button" name="myButton" value="view source" onClick="ViewSource()">
    </form>
    <br><br>
    <script>
    document.write('hello world');
    </script>
    </body>
    </html>
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #9
    GDS
    GDS is offline
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cut copy and paste isn't the most elegant interface for loading
    a file into an html editor. Ok, there seems to be no shortcut here.



    The use of FSO, as martin_narg mentioned earlier, will actually
    solve my problem. Besides, I can use it as a hta application,
    to get rid of those annoying alerts when useing FSO.

    But I am wondering: why are we denied to get easy access to
    the untampered source code?

    GDS

  • #10
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    'cause microsoft sucks.

    if you need help with the FSO, and reading files, let me know.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •