2017-04-25 45 views
0

如何停止選項卡更改jQuery的功能?下面給出了jquery js函數的代碼。如何停止jquery js函數的選項卡更改?

function move(){ 
addEventListener('load', function() { 
createProgressbar('progressbar1', '40s', function() { 
document.getElementById("close").style.display = "block"; 
document.getElementById("msg").style.display = "none"; 
}); 
}); 
} 

任何人都可以幫助我嗎?如果需要其他信息評論請。

+0

這個函數如何在你的標籤上調用?通過'onclick'?就像'第一個標籤'或者通過jquery代碼? –

+0

請參閱[this](http://stackoverflow.com/questions/1038643/event-for-when-user-switches-browser-tabs)。將這個anwer和setInterval結合起來,以實現全面的工作 – Ninjaneer

+0

@AlivetoDie是的,它通過點擊按鈕開始。 –

回答

0

如果您正在執行一個加載操作(比如說)在一個選項卡上,並且在加載過程中,如果切換到另一個選項卡,並且您需要停止加載的上一個進程,那麼可能不會發生。

但您可以做的是hide all elements(顯示與加載相關),只要您更改標籤,您不想顯示它們。

0

請參閱下面的主題。

playing = function() { 
 
    foo = window.setInterval(function() { 
 
     console.log('as') 
 
    }, 500); 
 
} 
 

 
$(window).blur(function(e) { 
 
    clearInterval(foo);//clear the interval..which inturn stop execution 
 
}); 
 

 
$(window).focus(function(e) { 
 
//will get executed when current tab is focused 
 
playing() 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
注意:在運行片段後點擊/ outof輸出區域以查看其工作。

相關問題