如何在不同域的另一个网页上加载外部网页的某个div [英] How to load a certain div of an external webpage on another webpage that is on a different domain

查看:79
本文介绍了如何在不同域的另一个网页上加载外部网页的某个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一个位于不同域的另一个网页上加载某个网页的div.

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

我已经尝试过:

<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

推荐答案

此jQuery的mod 允许您执行此操作. 查看!它使用YQL允许跨域请求.

This mod for jQuery allows you to do just that. Check it out! It uses YQL to allow cross domain requests.

一旦获得请求,它就会以JSON的形式显示,您可以通过ajax对其进行解析.这是我使用它的一种方式:

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);
    }
});

但我认为您也可以使用该链接上所示的.load来简单地执行此操作.

But I think you can also simply do it using the .load as is shown on that link.

这篇关于如何在不同域的另一个网页上加载外部网页的某个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆