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 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts

    saving source of a page to a variable

    I was wondering if there was a way to save the source of a page (same domain) to a variable. Any ideas?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,013
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    No, that cannot be done in Javascript - as already indicated.

    It is possible in PHP -

    http://us2.php.net/manual/en/function.file.php
    Last edited by Philip M; 08-12-2008 at 08:20 AM.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,346
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by Philip M View Post
    No, that cannot be done in Javascript - as already indicated.

    It is possible in PHP -

    http://us2.php.net/manual/en/function.file.php
    LOL, WTF!!!

    as who/what has already (incorrectly) indicated?



    Code:
    function IO(U, V) {
    //LA MOD String Version. A tiny ajax library. by, DanDavis
        var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        X.open(V ? 'PUT' : 'GET', U, false);
        X.setRequestHeader('Content-Type', 'text/html')
        X.send(V ? V : '');
    return X.responseText;}
    
    function pageSource() {return IO(window.location.href);}
    
    var myVariable = pageSource();
    alert(myVariable);
    does this code not work for anyone?

    i tested it in ie6, ie7,ff2,ff3,op9,op9.5, safari3...

    what can't do this ?
    Last edited by rnd me; 08-12-2008 at 01:44 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    Christian271 (08-13-2008)

  • #4
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    No, that cannot be done in Javascript - as already indicated.

    It is possible in PHP -

    http://us2.php.net/manual/en/function.file.php
    It was indicated that it's not possible to save the source of another domain but now I'm asking you can do it in the same domain.

  • #5
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rnd me View Post
    LOL, WTF!!!

    as who/what has already (incorrectly) indicated?



    Code:
    function IO(U, V) {
    //LA MOD String Version. A tiny ajax library. by, DanDavis
        var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        X.open(V ? 'PUT' : 'GET', U, false);
        X.setRequestHeader('Content-Type', 'text/html')
        X.send(V ? V : '');
    return X.responseText;}
     
    function pageSource() {return IO(window.location.href);}
     
    var myVariable = pageSource();
    alert(myVariable);
    does this code not work for anyone?

    i tested it in ie6, ie7,ff2,ff3,op9,op9.5, safari3...

    what can't do this ?
    Thanks I'll try that!

  • #6
    New Coder
    Join Date
    Jun 2008
    Location
    Vista, CA
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts
    It works, but I'm using frames (not iframes) and it shows the source for the frame I have it in, can you edit it to show the source of the main page?

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,346
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Code:
    function IO(U, V) {
    //LA MOD String Version. A tiny ajax library. by, DanDavis
        var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        X.open(V ? 'PUT' : 'GET', U, false);
        X.setRequestHeader('Content-Type', 'text/html')
        X.send(V ? V : '');
    return X.responseText;}
    
    function pageSource() {return IO(window.location.href);}
    function topSource() {return IO(top.location.href);}
    function parentSource() {return IO(parent.location.href);}
    
    var myVariable = topSource();
    alert(myVariable);
    
    var myVariable = parentSource();
    alert(myVariable);


    not sure of your setup, but one of these should cover you.


    -
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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