user
user

Reputation: 31

get a html element from another website (XSS)

How can I get a html element from another website directly into my site (not using an iframe).

For Example:

A page on another website has the following code (and nothing else);

<p>example text</p>

how can I get this into my website to be able to edit it. I can't directly copy the code because I want the code on my site to change in conjunction to the other site.

Upvotes: 3

Views: 3802

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

As you seem to have PHP tag, so if using PHP, you can use file_get_contents(), like

$html = file_get_contents('url_of_site/page.html');

or with DOMDocument, like:

$doc = new DOMDocument();
$doc->loadHTMLFile('http://some_site.com/');    

$html = $doc->getElementsByTagName('p');
print_r($html);

Note:: Due to Same Origin Policy, you cant do it with just javascript. If you want to do it with Javascript you need to create a proxy kinda stuff, like have a test.php file in your own server, add code to fetch content from other site into test.php file, and call this test.php file using javascript ajax.

Upvotes: 6

Related Questions