简体   繁体   English

在javascript中检测模式对话框

[英]Detect modal dialogs in javascript

Sample website for modal example : " http://vodkabears.github.io/remodal/#modal ", goal is to identify whether the website opened modal window or not. 模范示例网站示例:“ http://vodkabears.github.io/remodal/#modal ”,目标是确定网站是否打开了模态窗口。 Is there any way using java-script to achieve the goal ? 有什么方法可以使用Java脚本实现目标吗?

Note: I want to detect modal window and not alert/pop-up windows, without prior knowledge of modal window "id" or any attributes. 注意:我想检测模式窗口而不是警报/弹出窗口,而无需模式窗口“ id”或任何属性的先验知识。

A super simple way (in your case) could be just to check: 一种超级简单的方法(针对您的情况)可能只是检查:

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

However a better way as per the api could be to call inst.getState(); 但是,根据api的更好方法是调用inst.getState(); instead: 代替:

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();

Ref: https://github.com/VodkaBears/Remodal#methods 参考: https : //github.com/VodkaBears/Remodal#methods

Simple try this code 简单尝试一下此代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM