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 badges1 Answer
Reset to default 6As 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 badges1 Answer
Reset to default 6As 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
版权声明:本文标题:javascript - get a html element from another website (XSS) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745572303a2156808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论