1.同一个主域名
2.
3.hash调用(实际图片轮播编辑项目调用图片空间项目)
父页面:a.cshtml (域名假设www.aa.com)
b.cshtml(另一个域名的页面),
c.chstml(和a.cshtml同一个域名)
需求,点击a页面中的图片上传按钮,b页面显示(图片空间)显示,在这个iframe中选择某张图片,将地址传入a页面中
1.点击图片上传按钮时,a.cshtml页面的js里创建一个iframe,将src指向b.cshtml
gadgetSrc = 'http://stream.bb.com.cn/home/b?single=true&pageSize=10&maxNum=10#'
editorBox.delegate('.sys-images', 'click', function () {
currentInput = $(this).prev("input[name=picture]");
var index = $(this).parents(".edit-item").index();//图片位置
if (_selectDisable == true) {
document.getElementById("pic_frame").style.display = 'block';
document.getElementById("pic_frame").src=gadgetSrc+index
} else {
_selectDisable = true;
var html = '<iframe name="pic_frame" id="pic_frame" width="720" height="350" src="' + gadgetSrc +index+ '" style="border:none;display:block"></iframe>';
gadgetUploaderBox.html(html);
calIFHeight(IFHeightType.INSERT_PIC_IFRAME);
}
})
2.图片空间的内容加载出来,此时想要选中一张图片,将地址传入a页面中的input中,需要在b页面中创建一个iframe,src指向a的同一个域名(www.aa.com),即c.chstml
var iframe=document.createElement("iframe");
iframe.name = 'extral';
iframe.src='http://www.aa.com/Proxy/c'
iframe.height="0";
iframe.width="0";
iframe.style.border="0";
$("body").append(iframe);
<span style="white-space:pre"> </span>//选中一张图片<pre name="code" class="html"><span style="font-family: Arial, Helvetica, sans-serif;"> $(document).on("click", ".search-result a", function (){</span>
var src=$(this).find("img").attr("src").split('_'); var url=src[0]+'_'+src[1]; iframe.src='http://www.aa.com/Proxy/c'+location.hash+"|"+url; })
3.在c.cshtml页面中js
window.onhashchange = function () {
var s = parent.parent.document;
var hash = location.hash.split('|');
//alert(location.hash)
if (hash.length > 1 && !Number.isNaN(Number(hash[0].substring(1)))) {
var num = Number(hash[0].substring(1));
var x = $("input[name=picture]", s).eq(num);
x.val(hash[1]);
s.getElementById("pic_frame").style.display = "none";
}
if (hash[0] == "#pageBaner") {
$("#J_PreviewBox", s).find("img").attr({ "src": hash[1] }).css( "display","block");
$("#J_TadgadImage", s).val(hash[1]);
$(".iframe-box", s).css("display", "none");
}
}