![](/img/trans.png)
[英]Find out when the window.location.href of an iframe has changed with javascript (jquery)
[英]JavaScript: Check if window.location.href has been changed
我有以下代碼來顯示加載面板,例如,單擊按鈕並進行Ajax調用后:
$(document).on("click", function (e) {
window.LoadingPanel.Show();
});
在Ajax調用之后,以下代碼確保加載面板再次消失:
$(document).ajaxComplete(function() {
if (window.LoadingPanel != null) {
window.LoadingPanel.Hide();
}
});
但是在某些情況下,我會通過設置window.location.href
來根據Ajax調用的結果重定向到另一個頁面。 在這種情況下,我希望ajaxComplete
函數不要ajaxComplete
隱藏加載面板,直到重定向成功為止。
如果window.location.href已更改並且頁面將要重定向,如何檢查ajaxComplete
函數?
這可能不是解決此問題的好方法,但這就是我現在能想到的。
1.創建一個變量,調用isHide = true;
2.在jax調用中,如果不需要隱藏,則將Onsuccess函數設置為isHide = false。
3.在您的ajaxComplete中,請參閱以下內容
$(document).ajaxComplete(function(e) {
if (window.LoadingPanel != null && isHide) {
window.LoadingPanel.Hide();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.