iframe父子頁面通訊解決方案
有兩點要注意
onload載入完成再進行操作
子頁面延時獲取
場景是這樣的,父級頁面巢狀了多個iframe,report_six.html子級頁面按需載入數量,且每個子頁面渲染不同的資料。
父頁面for迴圈載入子頁面數量,動態生成id,根據對應的id,傳值給對應的子級頁面元素,一定要寫在onload裡面
下面是父頁面
<body>
<iframe src="report_one.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_two.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_three.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_four.html" frameborder="0" width="630" height="891"></iframe>
<iframe src="report_five.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_0" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_1" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_2" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_3" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="a_4" src="report_six.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="report_ten" src="report_ten.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="report_eleven" src="report_eleven.html" frameborder="0" width="630" height="891"></iframe>
<iframe id="report_nine" src="report_nine.html" frameborder="0" width="630" height="891"></iframe>
</body>
<script src="./js/jquery-2.1.4.js"></script>
<script>
if(obj.type == 3){
$(`<iframe src="report_one.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
$(`<iframe src="report_two.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
$(`<iframe src="report_three.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
$(`<iframe src="report_four.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
$(`<iframe src="report_five.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
var rank_a = obj.k.length;
for(var i = 0;i < rank_a;i++){
$(`<iframe id="a_` + i + `" src="report_six.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
}
$(`<iframe id="report_ten" src="report_ten.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
$(`<iframe id="report_eleven" src="report_eleven.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
var cancer = obj.c.length;
if(cancer > 0){
$(`<iframe id="report_nine" src="report_nine.html" frameborder="0" width="630" height="891"></iframe>`).appendTo(`body`);
}
window.onload = function(){
var rank_a = obj.m07.dis_risk.length;
for(var i = 0;i < rank_a;i++){
$(`#a_` + i).contents().find(`#rank`).val(i);
}
$(`#report_ten`).contents().find(`#change`).html(`四`);
$(`#report_eleven`).contents().find(`#change`).html(`五`);
$(`#report_nine`).contents().find(`#change`).html(`六`);
}
}
</script>
子級頁面帶有預設值的元素input#rank
接收資料,為了確定接收到引數,設定一個定時器,不等於預設值的情況下就表示接收成功,接收成功之後清除定時器執行業務程式碼
下面是子頁面
<body>
<section>
<div id="mainChart" class="chart"></div>
</section>
<input type="hidden" id="rank" value="a"/>
<script src="./js/echarts-all-3.js"></script>
<script>
var timer = setInterval(function(){
var rank_value = document.getElementById("rank").value;
if(rank_value != `a`){
clearInterval(timer);
//執行程式碼
}
},2000);
</script>
</body>
相關文章
- 父子頁面之間跨域通訊的方法跨域
- 頁面間通訊與資料共享解決方案簡析
- JQuery iframe頁面jQuery
- 使用 postMessage 解決 iframe 跨域通訊問題跨域
- javascript如何實現iframe父子頁面的相互操作JavaScript
- 禁止web頁面縮放解決方案Web
- Lora通訊解決方案對比
- Vue 元件通訊的解決方案Vue元件
- 音視訊即時通訊解決方案
- vue 父子元件通訊Vue元件
- iframe高度自適應解決方案
- Startalk(星語)——通用通訊解決方案
- Vue 父子元件的通訊Vue元件
- 父子元件之間通訊元件
- Iframe內部頁面高度賦值於其父頁面的Iframe標籤賦值
- 手機端頁面自適應解決方案
- iframe下重新整理頁面無法重新整理當前頁面的解決辦法
- 不同頁面通訊與跨域跨域
- Activity 與 Fragment 通訊(99%)完美解決方案Fragment
- Vue之父子、同級元件的通訊詳解Vue元件
- react父子、子父、兄弟通訊React
- js通過contentWindow控制iframe子頁面元素點選事件,並把值傳給父頁面JS事件
- Webpack4系列教程(六) 多頁面解決方案Web
- Webpack4系列教程(七) 單頁面解決方案Web
- 頁面無法輸入多個空格解決方案
- sharedWorker 實現多頁面通訊
- 融雲通訊解決方案 破解企業溝通痛點
- js如何從iframe子頁面中跳出JS
- 防止頁面被iframe惡意巢狀巢狀
- 我學react之父子元件通訊React元件
- vue父子元件通訊高階用法Vue元件
- vuejs如何設定父子通訊VueJS
- Vue2.0父子元件間通訊Vue元件
- Vue父子元件通訊小總結Vue元件
- vue--select父子元件通訊Vue元件
- Vue中父子元件通訊——元件todolistVue元件
- vue 2 0 元件:父子元件通訊Vue元件
- js和vue方法的相互呼叫(iframe父子頁面的方法相互呼叫)。JSVue