我有兩個網站A.com和B.com。我必須將B.com嵌入到A.com的iframe中。我無法在B.com上進行任何更改顯示微調,直到iframe加載一個http post響應
B.com僅適用於包含某些發佈數據的發佈請求。我有這樣的工作如下
<!--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加載完美的iframe響應後發送請求。但是B.com速度很慢。我想在#frameDiv中顯示一個微調框,直到iframe加載。我怎樣才能做到這一點?
這是我的嘗試:
$('#frameDiv').append($spinnerImage)
//Does not work, fires immediately
$ifr.load(function(){
//Hide the spinner image
});
//Does not work, fires immediately
$ifr.ready(function(){
//Hide the spinner image
});
如果B.Com是一個簡單的GET,並設置爲iframe的src屬性,jQuery的load方法的伎倆。但在這種情況下,它不是。
任何幫助表示讚賞:)
謝謝@charlie,這個工程。我找到了另一種方式,並將其作爲下面的另一個答案發布。請讓我知道您對該方法的看法 – labroo
是否對提交進行了這項工作?從來沒有嘗試過跨域 – charlietfl
是的,它的工作原理,跨域也:) – labroo