www.webdeveloper.com
Results 1 to 13 of 13

Thread: Reading information from another site?

  1. #1
    Join Date
    Jun 2007
    Posts
    28

    Reading information from another site?

    Hi,
    I was wondering: is it possible to get read the line on this site (not mine) and to make it available for javascript? If the answer is yes: how can i do this?

    kind regards,
    Knstr

    note: i don't have much experience with javascript so keep it simple please

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Yes. You can either load the page into a hidden iFrame, or use a server-side language. Only the former can be accomplished by just JavaScript.

  3. #3
    Join Date
    Jun 2007
    Posts
    28
    Thanks for the reply declan.
    About the iframe: that's not an option for me as I have to do some calculations with the numbers you saw on the site...
    About the server-side language: should i use php then?
    if yes: how do i move this topic? what would this php script look like?

  4. #4
    Join Date
    Aug 2007
    Posts
    3,767
    Well, you can still use the information from the iFrame, but the PHP solution would be my preferred anyway.
    Include tutorial. From what I know of PHP, that will work for an internal file, but you can read all about that at php.net.

  5. #5
    Join Date
    Feb 2009
    Location
    UK
    Posts
    142
    Declan - I have asked this question and seen similar posts and they all said it was impossible on client-side. Is the hidden IFRAME wheeze an exception to received wisdom?

    I will try it soon anyway.

    TIA

    I was going to hide my IFRAME during the inspection phase to speed the process, but I found that rendering proceeds after onLoad fires anyway. So I guessed it would not improve anything.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You can not establish a JavaScript relationship between documents belonging to different domains, so that in an iframe everything you can do is to display that document as it is, but you can not "touch" it (read it) using javaScript. Only a proxy server-side application can do that. That means you need a combination AJAX + proxy to read the information from another domain and use it on your document as a JavaScript variable.
    Last edited by Kor; 08-16-2010 at 09:09 AM.

  7. #7
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by Declan1991 View Post
    Yes. You can either load the page into a hidden iFrame, or use a server-side language. Only the former can be accomplished by just JavaScript.
    As far as I know the former solution is not valid. Cross-domain JavaScript relationship is forbidden by default

  8. #8
    Join Date
    Jun 2007
    Posts
    28
    well, i decided to do everything in php (so including the calculations that i was planning to do in javascript).
    This is what i made up:
    PHP Code:
    <?php
    $raintimestr 
    file_get_contents('http://gps.buienradar.nl/getrr.php?lat=52.2167&lon=5.01667');
    $raintime split("[\n| ]+",$raintimestr);
    $b=(10^(($raintime[0]-109)/32));
    echo 
    $b;
    ?>
    I however failed to do the calculation - $b=(10^(($raintime[0]-109)/32)); - properly...
    I keeps saying that -9 is the answer and that is not right...

  9. #9
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by knstr View Post
    well, i decided to do everything in php (so including the calculations that i was planning to do in javascript).
    This is what i made up:
    PHP Code:
    <?php
    $raintimestr 
    file_get_contents('http://gps.buienradar.nl/getrr.php?lat=52.2167&lon=5.01667');
    $raintime split("[\n| ]+",$raintimestr);
    $b=(10^(($raintime[0]-109)/32));
    echo 
    $b;
    ?>
    I however failed to do the calculation - $b=(10^(($raintime[0]-109)/32)); - properly...
    I keeps saying that -9 is the answer and that is not right...
    And how could we know which is the correct value? We don't know what is the response. We don't know which are the values of your variables...

  10. #10
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by Kor View Post
    As far as I know the former solution is not valid. Cross-domain JavaScript relationship is forbidden by default
    I always use a server-side solution, so you're probably right. I was under the impression that you could access the contents of an iFrame on the page, but not call any JavaScript or anything like that. I must have been wrong.

    preg_split is the better method to use first of all.

    What exact calculation are you trying to do? The present one is this, which I somehow doubt is what you want. Though that's not -9 so the values on the page must have changed recently.
    Code:
    $b=(10^((000-109)/32));

  11. #11
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    I was under the impression that you could access the contents of an iFrame on the page
    Kor is correct; access is denied.

  12. #12
    Join Date
    Jun 2007
    Posts
    28
    The outcome of the calculation is a rainfall depth, so in mm/h. That's always positive, and -9 isn't .
    If $raintime[0] is 0, the outcome should be 3.9E-4 mm/h (so almost nothing...)
    $raintime[0] is a value between 000 and 255 i think... But i think the problem is that its still a string, not a number.
    I tried to convert the raintime[0] to a number using:
    PHP Code:
    settype($raintime[0], "float"); 
    but that didn't work.

    I hope you guys can help me. Thanks for the effort so far!

  13. #13
    Join Date
    Aug 2010
    Posts
    41

    Iframe wont work

    You cannot access the content of the 3rd parties content using iframe. Even if the page(iframe src) is in your application you cannot read the body (i mean the whole content of the iframe) from javascript. If you try to do you will get the error "Access is denied".

    But you can get the content of a particular text box/div/button etc you can get it. Still the src of the iframe should be in your application. 3rd parties link wont work.

    Regards,
    P. Rajan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles