我想为其他网站提供我网站的横幅,但我想将横幅保留在我的服务器上,并让它们包含在 javascript 中,就像 Facebook 插件/谷歌广告一样。
横幅托管在站点 A 上。站点 BI 具有以下代码:
<div id="bannerContainer"></div>
<script type="text/javascript" src="http://mysite.com/plugins/includebanner.js"></script>
includebanner.js 执行 AJAX 调用以获取横幅并将其放置在bannerContainer 中,但出现错误:
Origin http://lventas.com is not allowed by Access-Control-Allow-Origin.
如何允许所有网站包含横幅?是否有其他简单的方法可以包含来自其他站点的站点 A 中托管的横幅?
编辑:
This is the script that requests the content:
function ajax(url, id_contenedor)
{
var pagina_requerida = false;
if (window.XMLHttpRequest)
{
pagina_requerida = new XMLHttpRequest ();
} else if (window.ActiveXObject)
{
try
{
pagina_requerida = new ActiveXObject ("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
pagina_requerida = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}
else
return false;
pagina_requerida.onreadystatechange = function ()
{
cargarpagina (pagina_requerida, id_contenedor);
}
pagina_requerida.open ('GET', url, true); // asignamos los métodos open y send
pagina_requerida.send (null);
}
function cargarpagina (pagina_requerida, id_contenedor)
{
if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == - 1))
document.getElementById (id_contenedor).innerHTML = pagina_requerida.responseText;
}
ajax('http://lujanventas.com/plugins/banner/index.php', 'banner-root');