admin管理员组

文章数量:1022705

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.

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.

Share Improve this question edited Oct 18, 2013 at 13:01 user asked Sep 20, 2013 at 3:05 useruser 311 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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./');    

$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.

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.

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.

Share Improve this question edited Oct 18, 2013 at 13:01 user asked Sep 20, 2013 at 3:05 useruser 311 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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./');    

$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.

本文标签: javascriptget a html element from another website (XSS)Stack Overflow