[英]Displaying certain div from external site on my site
I am making a website and I'd like to display a portion of an external website seamlessly on my own. 我正在制作一个网站,我想无缝显示自己的外部网站的一部分。 For example a certain div element.
例如某个div元素。 I understand this is not straightforward due to the same origin policy.. Is there a way to bypass this?
我知道由于相同的原产地政策,这并不简单。是否可以绕过此方法? For example dumping the website onto a local file and then loading it?
例如将网站转储到本地文件然后加载? Or screenshotting the website portion and linking to the image?
还是截图网站部分并链接到图像?
you can do this by 你可以这样做
<?php
$url = "http://www.bla.com";
$page_all = file_get_contents($url);
preg_match('#<div class="hola">(.*)</div>#ms', $page_all, $div_array);
echo "<pre>";
print_r($div_array[0]);
echo "</pre>";
?>
Note php solution requires allow_url_fopen
option enabled thanks @shiplu.mokadd.im 注意 php解决方案需要启用
allow_url_fopen
选项,谢谢@ shiplu.mokadd.im
or by ajax 或通过ajax
$.ajax({
url: 'http://bla.com',
type: 'GET',
success: function(res) {
var divcontent= $(res.responseText).find('#div_name').html();
$('#blabla').html(divcontent);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.