Results 1 to 7 of 7

Thread: Iframe SSI II Outside domain question

  1. #1
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Iframe SSI II Outside domain question

    1) Script Title: iframe ssi script II

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...iframessi2.htm

    3) Describe problem: In the script instructions I know it says the pages all have to be in the same domain. But I was wondering if there might be room for one exception.

    We have a service providing dynamic content for our site. These pages are created without wrapping and we include them in our site in an iframe. We have full access to the server that these pages are on so I was wondering if there was a way to include a script on each page to guage the size of the page and then pass the size variable to the parent page for resizing of the iframe.

    Moving the pages to our server is not an option due to other issues. Any way to do this??

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Unfortunately, the same security considerations that prevent the top page from querying the contained page for information, prevent it from receiving information actively sent from the contained page in these situations. There may be a workaround if your domain has PHP or another server-side language available to it but, that is beyond my expertise. If your domain does have PHP available, there are a few folks here at the forums who could probably help you if you posted about this in the PHP forum.

    The basic idea is that with the intervention of PHP, a new page can be assembled on your domain with the content of the page from the other domain. Once this is accomplished, the script that you are using can operate without the restrictions mentioned on the demo page as long as it is this new page from the same domain that gets loaded into the iframe.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    In short, here's some PHP code that would help you--
    PHP Code:
    <?php
    ob_start
    (); //start output buffer*
    include('http://address.com/page/and/stuff.php'); //include the page
    //*if include is called normally, it just outputs it right away
    //output buffer grabs that info instead
    $page ob_get_contents(); //now store to variable
    $page str_replace("'",''',$page); //replace ' with html entity
    //if not, that will conflict in javascript later on
    ob_end_clean(); //end output buffer
    ?>

    Do your javascript stuff....
    <script type="text/javascript">
    ....
    var page = '<?php echo $page?>';
    ....
    </script>
    HOWEVER, note that it will be a problem if the included page contains stuff that conflicts with javascript, though I'm not sure what it is. I included a line changing ' to &#39;, so that should be good, but it may be a bit more complex.

    However, this doesn't solve your problem, but it does get you ALL of the html, etc. from the page.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The page that contains the iframe is a php page so we are good on that. Not sure if I follow all that, but it sounds interesting. I'll check into it. Thanks.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Each line is commented. It's really very simple.

    The include statement gets the text (html) of the page it has in parentheses... any page. Then it outputs with the echo later on as a variable into a javascript variable.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I just tried this out on a domain that has PHP and had problems with the str_replace (it gave an error). As a result, the javascript didn't work but, it really doesn't need to for this. I changed the code to:

    PHP Code:
    <?php
    ob_start
    (); //start output buffer*
    include('http://some.com/2006/directions.htm'); //include the page
    //*if include is called normally, it just outputs it right away
    //output buffer grabs that info instead
    $page ob_get_contents(); //now store to variable

    ob_end_clean(); //end output buffer
    ?>

    <?php echo $page?>
    saved it as directions.php and got the directions page from the other domain. Style and images were not available but, the content was all there. But, this only worked retrieving a page from another domain that was on the same server and that was actually in a subdirectory of the retrieving domain's files. I couldn't get it to grab Google's home page or a page from another domain entirely that was a plain HTML file with just the word 'Hi' on it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm. Not sure what's wrong with the str_replace.

    http://www.php.net/manual/en/function.str-replace.php

    OOOH

    Grrr. Stupid interpreting of ascii characters.

    $page = str_replace("'",''',$page);

    it SHOULD be:
    $page = str_replace("'",'&#39;',$page);

    Sorry about that.

    As for inputting to a variable, I was assuming you were going to try to analyze the html of the page, so figured that was the best way.

    However, there's another way to do it.

    1. use the PHP to get the html of the iframe in question and bring that to your server.
    If you aren't trying to echo/alter the text of that site in a particular fashion, then just use include('http:///') and be done with it. You don't need to use any of the output buffer stuff, or the echo, etc. Just output directly.

    2. get the height/width values.

    3. to avoid having screwed up pages (missing linked content, like styles and images), use the REAL page, but with the height/width from the page in question.


    Additionally, this is similar to a proxy, so you could actually parse the html and unlocalize the links so that they work.

    That wouldn't be too hard.

    Append to each href/src/etc the location of the page asked for, minus the filename itself. And you would need to account for ../ and / commands at the starts of links. But that is possible.


    It all depends on what you plan to DO with the page.

    The PHP I have supplied does it's job. Now it's up to javascript.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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