简体   繁体   English

使用jQuery将外部网页添加到div

[英]use jquery to add external webpage to div

I have the following piece of code to load a GIF while ajax takes a div and appends some content: 我有以下代码来在ajax需要div并附加一些内容的同时加载GIF:

var loader = '<img id="loader" src="loading.gif"/>';

$(loader).appendTo('#container').load(function() {
    $('#container').find('#loader').delay(3000).fadeOut(function() {
        $('#container').append('content')
    })
});

How can I modify this code so instead of appending 'content' , it would append a div from an external webpage. 我该如何修改此代码,而不是附加'content' ,而是从外部网页附加div

For example the GIF will fadeout, and inside of the container div will be www.somesite.com #somediv . 例如,GIF将消失,而容器div内部将是www.somesite.com #somediv

Thanks, 谢谢,
Katie 凯蒂

You can't because of Same Origin Policy restrictions. 您不能因为同源政策限制。

You could, however, use an iframe to embed part a whole page in your page. 但是,您可以使用iframe在页面中嵌入整个页面的一部分。

Cross-domain XHR is possible by using the YUL library by Yahoo!. 通过使用Yahoo!的YUL库 ,可以实现跨域XHR。 It basically uses the server to fetch the content for you to bypass the policy as Hamish mentioned. 它基本上是使用服务器来获取内容的,以便您绕开Hamish提到的策略

For more information, please see: The jQuery Cross-Domain Ajax Guide 有关更多信息,请参见: jQuery跨域Ajax指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM