How to load a certain div of an external webpage on another webpage that is on a different domain

后端 未结 2 1911
深忆病人
深忆病人 2021-01-14 14:36

How can you load a certain div of a webpage on another webpage that resides on a different domain.

I have tried this:

相关标签:
2条回答
  • 2021-01-14 15:12

    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.

    0 讨论(0)
  • 2021-01-14 15:19

    This 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.com',
        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.

    0 讨论(0)
提交回复
热议问题