开发者

Insert content from one website into another

开发者 https://www.devze.com 2023-04-11 19:18 出处:网络
I have two websites which display the same content. I would like to be able to have the content on one site and display it on the other (so I only have开发者_运维知识库 to update one site when I need

I have two websites which display the same content. I would like to be able to have the content on one site and display it on the other (so I only have开发者_运维知识库 to update one site when I need to make amends).

Is there a way to do this using jquery??

Something like this:

$(".site2div).append($("http://www.mysite.com").find(".site1div").innerhtml());


You will have cross-domain security issues:

http://jsfiddle.net/KYVFy/

$(document).ready(function() {
  $.get('http://www.google.com', function(data) {
    $("#jackedContent").html(data);
 });
});

So more likely you will have to have some type of "web proxy service" on the server side to communicate across domains.


If your minimum browser to support is IE8 or higher, there's a new standard with better handles this: Cross-Originl Resource Sharing (CORS) [wiki] [browser support]. As others have pointed out the browser fundamentally controls which domains you can access content from, however CORS allows the domain to specify who can access the content. If you control both websites or are partnered with the other website setting up an allow rule for CORS might be worth looking into. Again, only IE8 and above currently supports this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号