Javascript 显示微调器,直到使用http post响应加载iframe
我有两个网站A.com和B.com。我必须将B.com嵌入A.com的iframe中。我不能在B.com上做任何更改 B.com只处理带有某些post数据的post请求。我的工作如下Javascript 显示微调器,直到使用http post响应加载iframe,javascript,jquery,iframe,Javascript,Jquery,Iframe,我有两个网站A.com和B.com。我必须将B.com嵌入A.com的iframe中。我不能在B.com上做任何更改 B.com只处理带有某些post数据的post请求。我的工作如下 <!--This is the div inside which I will embedd the iframe--> <div id="frameDiv"></div> <script type="text/javascript"> //Create
<!--This is the div inside which I will embedd the iframe-->
<div id="frameDiv"></div>
<script type="text/javascript">
//Create iframe
var $ifr = $('<iframe name="myFrame" id="myFrame"></iframe>');
//create form
var $form = $('<form action="B.com" method="post" target="myFrame"></form>');
//Append hidden field to form to pass postData
$form.append($('<input type="hidden" name="dataName"><input>').val('data'));
//Append form to the iframe and then append iframe to the div
$('#frameDiv').append($ifr.append($form));
$form.submit();
</script>
如果B.Com是一个简单的get,并且被设置为iframe的src属性,那么jQuery加载方法就完成了这个任务。但在这种情况下,情况并非如此
非常感谢您的帮助:)您可以尝试在iframe的初始加载事件处理程序中绑定一个新的加载事件侦听器。以下内容适用于同一域iFrame:
$ifr.load(function(){
/* bind new load event listener for next load*/
$(this).load(function(){
/* hide spinner*/
})
});
@charlietfl的答案是正确的,而且有效。我只是想和大家分享我发现同样有效的另一种方法 只需将iframe的背景设置为微调器:) 加载B.com时,新文档将隐藏微调器
你知道哪种方法更可取吗?谢谢@charlie,这很有效。我也找到了另一种方法,并将其作为另一个答案发布在下面。让我知道你们对这个方法的看法我猜,因为动态Iframe的主体上并没有设置css,它是透明的…非常有趣的解决方案!如果正在加载的iframe具有透明背景,则此操作不起作用,对吗?
$ifr.load(function(){
/* bind new load event listener for next load*/
$(this).load(function(){
/* hide spinner*/
})
});
#myFrame
{
background-image: url('/content/images/spinner.gif');
background-repeat: no-repeat;
}