Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a certain div of an external webpage on another webpage that is on a different 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.com #divname');</script>

But it doesnt work when the page to load is on another domain

like image 436
sebas Avatar asked Nov 25 '25 14:11

sebas


1 Answers

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.

like image 187
Zac Avatar answered Nov 27 '25 05:11

Zac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!