Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
有兩個頁面parent.html和child.html,在parent頁面里面通過window.open打開了child頁面,child頁面執行完代碼之后想要刷新parent頁面,然后立即查看到修改后的效果,那么我們就要在child里面直接能夠刷新parent頁面,這樣就可以實現這樣的效果。
1.1打開了parent.html頁面
1.2在parent頁面打開了child頁面
1.3child頁面點擊確定按鈕之后刷新了父頁面parent
2 parent.html內容:
<!DOCTYPE html>
<html>
<head>
<title>parents</title>
<meta charset="UTF-8">
<script language="javascript" type="text/javascript">
function openWin() {
window.open('child.html', '_blank','width=500,height=400,top=200,left=400');
}
//定義callback方法,用于回調
function callback() {
refreshWin();
}
//刷新當前頁面
function refreshWin() {
//調用刷新頁面的方法,刷新當前頁面,結果會再次彈出222
window.location.reload();
}
//剛記載的時候彈出222
function show(){
alert(222);
}
</script>
</head>
<body onload="show()">
<input id="btnAdd" type="button" onclick="openWin();" value="添加" />
</body>
</html>
3 child.html內容:
<!DOCTYPE html>
<html>
<head>
<title>child</title>
<meta charset="UTF-8">
<script language="javascript" type="text/javascript">
function formSubmit(){
window.opener.callback();//上述執行完成后,調用打開頁面的callback方法,此處是調用主頁面的callback方法
window.close();//當前頁面關閉
}
</script>
</head>
<body>
<input id="onSub" type="button" onclick="formSubmit();" value="確定">
</body>
</html>
4 通過這樣的操作很容易在子頁面操作父頁面所有的方法,感覺很方便,整理一下供大家參考。
歡迎關注我的頭條號,謝謝大家!
項目當中如果做新增/修改/刪除等等操作通常情況下都需要刷新數據或者刷新當前頁面.
通過location.reload和$router.go(0)都可以實現頁面刷新,它利用瀏覽器刷新功能,相當于按下了f5鍵刷新頁面
優點:足夠簡單
缺點:會出現頁面空白,用戶體驗不好
天給大家說一下HTML父頁面調用iframe子頁面中js變量和方法,
以jQuery為例,假如子iframe為
現在obj為jQuery對象
獲取子頁面DOM
調用子頁面js變量和方法
還有一種方法,根據iframe的name獲取
小編會不定時更新前端相關的知識,有興趣的話歡迎大家加群142991222一起討論交流學習。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。