2016-12-06 55 views
0

我有一種模式播放的視頻,但是當我關閉模式時,視頻會繼續在背景中播放(並且聲音會繼續播放)。模式隨#modal添加到網址中打開,當它關閉時,鏈接到#refresh。爲什麼當#refresh被加載時,這段代碼不會刷新頁面?當我關閉模式時,我將如何刷新頁面?

if(window.location.href.indexOf("refresh") > -1) { 
    setTimeout(function(){ 
    window.location = "products.html"; 
    },1000); 
} 

<a href="#refresh"><img src="images/x.jpg"><meta http-equiv="refresh"></a> 

當返回到#refresh時,頁面本身不刷新,因此只有在用戶刷新頁面之後才能觸發此功能。

+1

它需要處於偵聽按鈕被點擊的事件處理程序中。 –

回答

0

首先尋找一個哈希使用window.location.hash所以像:

if(window.location.hash.indexOf("refresh") > -1) { 

和刷新使用window.location.href這樣:

window.location.href = "products.html"; 
1
document.getElementById('refresh').addEventListener('click', function(e) { 
    e.preventDefault(); 
    window.location.reload; 
}); 
+0

這似乎沒有工作出於某種原因@Carl Edwards – hpq

+0

您是否收到任何錯誤?什麼不工作? –

相關問題