Is there any way to embed an external web page without using an iframe? I have access to both sites, I just want the page that the content is embedded on to resize based on the content that is embedded (it will change over time, and be on multiple sites).
Thanks!
EDIT: I don’t think any kind of AJAX would work because it’s cross-site, and JavaScript doesn’t let you load off-site content (as far as I’m aware).
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You could load the external page with jquery:
<script>$("#testLoad").load("http://www.somesite.com/somepage.html");</script>
<div id="testLoad"></div>
//would this help
Method 2
Or you could use the object tag:
<!--[if IE]> <object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="http://www.google.be"> <p>backup content</p> </object> <![endif]--> <!--[if !IE]> <--> <object type="text/html" data="http://www.flickr.com" style="width:100%; height:100%"> <p>backup content</p> </object> <!--> <![endif]-->
Method 3
Question is good, but the answer is : it depends on that.
If the other webpage doesn’t contain any form or text, for example you can use the CURL method to pickup the exact content and after then showing on your page. YOu can do it without using an iframe.
But, if the page what you want to embed contains for example a form it will not work correctly , because the form handling is on that site.
Method 4
What about something like this?
<?php
$URL = "http://example.com";
$base = '<base href="'.$URL.'" rel="nofollow noreferrer noopener">';
$host = preg_replace('/^[^/]+///', '', $URL);
$tarray = explode('/', $host);
$host = array_shift($tarray);
$URI = '/' . implode('/', $tarray);
$content = '';
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if(!$fp) { echo "Unable to open socked: $errstr ($errno)n"; exit; }
fwrite($fp,"GET $URI HTTP/1.0rn");
fwrite($fp,"Host: $hostrn");
if( isset($_SERVER["HTTP_USER_AGENT"]) ) { fwrite($fp,'User-Agent: '.$_SERVER
["HTTP_USER_AGENT"]."rn"); }
fwrite($fp,"Connection: Closern");
fwrite($fp,"rn");
while (!feof($fp)) { $content .= fgets($fp, 128); }
fclose($fp);
if( strpos($content,"rn") > 0 ) { $eolchar = "rn"; }
else { $eolchar = "n"; }
$eolpos = strpos($content,"$eolchar$eolchar");
$content = substr($content,($eolpos + strlen("$eolchar$eolchar")));
if( preg_match('/<heads*>/i',$content) ) { echo( preg_replace('/<heads*>/i','<head>'.
$base,$content,1) ); }
else { echo( preg_replace('/<([a-z])([^>]+)>/i',"<\1\2>".$base,$content,1) ); }
?>
Method 5
Why not use PHP! It’s all server side:
<?php print file_get_contents("http://foo.com")?>
If you own both sites, you may need to ok this transaction with full declaration of headers at the server end. Works beautifully.
Method 6
HTML Imports, part of the Web Components cast, is also a way to include HTML documents in other HTML documents. See http://www.html5rocks.com/en/tutorials/webcomponents/imports/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0