DEVOPS
DEVOPS

Reputation: 18790

How to display other sites content in our sites with out using iframe?

How to display other sites content in our sites with out using iframe? Is it possible to load one sites file details in our site with out using the iframe.

Upvotes: 0

Views: 3815

Answers (6)

KalenGi
KalenGi

Reputation: 2077

You can achieve it with the code below. Two notes though:

1) I'm not sure this works with IE

2) Heed the advice put out by @Paul_Tomblin and @Codemwnci about getting permission to display a different site's content.

The html part is:

<object id="external-page" type="text/html" data="" > 

</object>

The javascript part in jquery is:

$("#external-page").attr("data", "http://foreign-site.net/foreign-page.html");

Upvotes: 0

Joyce Babu
Joyce Babu

Reputation: 20654

You cannot use Ajax due to the Same Origin policy. There are two ways to circumvent this.

  • Use a proxy - As Gazler said, you can create a proxy script in PHP to download the file. Call the file proxy script from your javascript.

  • Use JSONP - You can use JSONP for cross domain communication. Make sure you read the cautionary note

Upvotes: 0

Dave
Dave

Reputation: 506

jQuery should be able to do this (I'm assuming you're using jQuery since you've tagged the question with it). You should look at the documentation on the .load() method as that has an excellent example in there

Edit: As Nick points out below, this will only work for pages on the originating site due to the same origin policy in javascript

Upvotes: -2

Codemwnci
Codemwnci

Reputation: 54884

The way I have achieve this in the past is as follows

<?php
$handle = fopen("http://someurl", "rb");
$contents = stream_get_contents($handle);
fclose($handle);

echo "<div>Your Content</div>";
echo "<div>";
print($contents);
echo "</div>";
echo "<div>More of your contents";

?>

Upvotes: -1

gblazex
gblazex

Reputation: 50101

It is possible and quite easy with YQL.

The Yahoo! Query Language is an expressive SQL-like language that lets you query, filter, and join data across Web services. With YQL, developers can access and shape data across the Internet through one simple language, eliminating the need to learn how to call different APIs.

Upvotes: 1

Gazler
Gazler

Reputation: 84140

You can use the PHP Curl library.

Upvotes: 3

Related Questions