Show the true html source of a web page (including that generated by script).

Discussion in 'Javascript' started by Sandip Chitale, Nov 20, 2003.

  1. // Bookmarklet by Sandip Chitale ()
    // Function: Show the true html source of a web page (including that generated by script).
    // Usage: 1. Copy these to a file (say - 'c:/bookmarklets/viewfinalsource.js')
    // 2. Visit any website
    // 3. copy and paste the following line in your address bar starting with the word 'javascript:'
    // javascript:void((function() {var
    element=document.createElement('script');element.setAttribute('src','c:/bookmarklets/viewfinalsource.js');
    document.body.appendChild(element)})())
    // 4. Alternatively, create a bookmark (or also a Links toolbar shortcut in case of IE) for it to access the functionality
    with a single click.
    function viewFinalSource() {
    var _console = null;
    // open a window the first time we are called, or after an existing
    // console window has been closed.
    if ((_console == null) || (_console.closed)) {
    _console = window.open("","console","width=600,height=300,resizable,scrollbars=yes");
    // open a document in the window to display plain text
    _console.document.open("text/plain");
    }
    var gt = /\>/g;
    var lt = /\</g;
    var el = /\n\s*\n/g;
    _console.document.writeln(document.documentElement.innerHTML.replace(gt,">\n").replace(lt,"\n<").replace(el,"\n"));
    }
    viewFinalSource();
     
    Sandip Chitale, Nov 20, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page