admin管理员组文章数量:1429841
How can you load a certain div of a webpage on another webpage that resides on a different domain.
I have tried this:
<div id="m"></div>
<script>$('#m').load(' #divname');</script>
But it doesnt work when the page to load is on another domain
How can you load a certain div of a webpage on another webpage that resides on a different domain.
I have tried this:
<div id="m"></div>
<script>$('#m').load('http://something. #divname');</script>
But it doesnt work when the page to load is on another domain
Share Improve this question edited Dec 6, 2011 at 3:08 Kevin Ennis 14.5k2 gold badges46 silver badges44 bronze badges asked Dec 6, 2011 at 2:53 sebassebas 7421 gold badge7 silver badges21 bronze badges2 Answers
Reset to default 6This mod for jQuery allows you to do just that. Check it out! It uses YQL to allow cross domain requests.
Once you get the request it appears as JSON which you can parse out through ajax. This is one way I have used it :
$.ajax({
url: 'http://something.',
type: 'GET',
success: function(res) {
var loadIt = $j(res.responseText).find('#divname').html();
$('#m').html(loadIt);
}
});
But I think you can also simply do it using the .load as is shown on that link.
You need to use a technique called web scraping on your server side.
Almost all server side programming languages have a library to do this. If you are familiar with JavaScript you can use node.js. Once you have the div
you require scraped and available, you can serve it to the client using Ajax which can also be done easily with node.js.
For more, look at this article.
本文标签:
版权声明:本文标题:php - How to load a certain div of an external webpage on another webpage that is on a different domain - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745443366a2658547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论