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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get Var from webpage source

    Hi,

    I would like to ask if there is anyway to get a variable from any webpage source using javascript.

    Something like javascript: document.getelement?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,111
    Thanks
    75
    Thanked 4,335 Times in 4,301 Posts
    Sure, document.NameOfVariable

    But it only works if you have permission to access the page in question, and that generally means that the web page must come from the *SAME DOMAIN* as the page doing the "getting".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by WhiteCol View Post
    I would like to ask if there is anyway to get a variable from any webpage source using javascript.
    If you mean get a variable from a window's parent window then in the parent window
    Code:
    <script type="text/javascript">
                var parVar = 'qwerty';
                window.open('childPage.html');
    </script>
    and in childPage.html
    Code:
    <script type="text/javascript">
       alert(window.opener.parVar);
    </script>
    or if you want to get a variable from a child window, then in the child page

    Code:
    <script type="text/javascript">
         var childVar = 'zxcvb';
    </script>
    and in the parent window

    Code:
    <script type="text/javascript">
               var myWin = window.open('childPage.html');
                alert(myWin.childVar);
    </script>
    Last edited by webdev1958; 08-28-2011 at 07:28 AM.


  •  

    Posting Permissions

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