2016-11-30 103 views
0

模態示例網站示例:「http://vodkabears.github.io/remodal/#modal」,目標是識別網站是否打開模式窗口。有沒有使用java腳本來達到目標​​的方法?在javascript中檢測模態對話框

注意:我想檢測模態窗口而不是預警/彈出窗口,而無需事先了解模態窗口「ID」或任何屬性。

+0

爲什麼你想要它? –

+0

你已經寫了一些代碼嗎?我的意思是你有基地嗎? – bash0ne

回答

0

一個超級簡單的方法(在你的情況下)可能只是爲了檢查:

if ($('.remodal-is-opened') !== undefined) { 
    //open! 
} 

但更好的方法是按照API可以調用inst.getState();代替:

var inst = $('[data-remodal-id=modal]').remodal(); 

/** 
* Opens the modal window 
*/ 
inst.open(); 


/** 
* Returns a current state of the modal 
* @returns {'closed'|'closing'|'opened'|'opening'} 
*/ 
inst.getState(); 

參考: https://github.com/VodkaBears/Remodal#methods

0

簡單試試這個代碼

if($('.remodal-is-opened')){ 
console.log("modal open") 
}else console.log("modal closed");