下面的代碼可以正常工作,唯一的問題是click事件被排隊,比如setTimeout被每次點擊所調用,彈出窗口會多次出現。如何使彈出只出現當用戶點擊並確保每個彈出之間的差距可以說4秒Javascript:如何停止點擊事件排隊?
var showpopup = 1;
var check = true;
var seconds = 4000; // change the frequency here current frequency = 2 seconds
var url = "https://www.fb.com"; // change the url here
var strWindowFeatures = "toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=" +screen.width
+ ",height=" +screen.height;
function popup (event)
{
event.stopPropagation();
if (showpopup === 1)
{
//if
(navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Windows
Phone|Opera Mini|IEMobile/i))
//{
if (check == true)
{
window.open(url , '_blank' , strWindowFeatures);
showpopup++;
check = false;
}
//}
}
else
{
setTimeout(checkValue, seconds);
}
}
function checkValue()
{
showpopup = 1;
check = true;
}
window.onclick = popup(event);
我本來認爲'window.onclick =彈出(事件);'不設置點擊處理程序,因爲你正在設置(用一個空的事件參數調用彈出窗口)的返回值來處理點擊,而不是設置函數本身,如'window.onclick = popup;' – James
對不起,這是我的錯誤張貼舊版本沒有檢查 – Alien128