简体   繁体   中英

Loading external website with PHP file

I'm using JQuery to resize an iframe to make it have the same height as it's content, it works perfectly though it only works if the content is in the same domain.

I need to display external content so I'm making the iframe point to a file in my server which in turn should display the external content:

<iframe src="frame.php" scrolling="no" frameborder="0" noresize="noresize" style="width:100%; border: 1px solid black;">

How do I make frame.php display the content of the external domain?

In case you need more info here is the answer on how to do it (he explains everything excepts how to display content in the php file): AutoHeight IFrame

Thanks

So you want to fetch the contents of an external site?

This will work, but it'll break the layout when the target page has non-absolute URLs and relative links:

frame.php :

<?php

echo file_get_contents($_GET['url']);

?>

<?php echo file_get_contents( "http://example.com" );?>

Somethhing like that will do

Unfortunately, php isn't the correct language to be doing this. In order to determine the height of the document in the iframe, you would need to make a javascript call from the parent document (where the iframe element is) to the document referenced in the src of the iframe.

In the case where the src of the iframe is on your domain, you have full permission to use the DOM of the document to get the document's height, as per the same origin policy. When you load a document from another domain, you do not have permission to query for the height. What the answerer of your question seems to be suggesting is setting up a proxy on your site so that the same origin policy would be circumvented.

However, there going to be other issues with that (ie relative links on the proxied page, etc.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM