javascript - 如何在我的网页上每 15 秒打开一次神奇的弹出窗口
问题描述
我在我的网页上使用 JavaScript 代码,但它在 10 秒后仅出现 2 次,我想每 15 秒显示一次弹出窗口,比如无限次,请帮帮我,我无法找到解决方案,这里是 JavaScript 代码:
$(window).load(function() {
setTimeout(function() {
$.magnificPopup.open({
items: {
src: 'Contact_Form/index.html'
},
type: 'iframe',
mainClass: 'my-mfp-zoom-in'
});
}, 10000);
});
还有一件事,如果有人点击我的网页,就会出现这个弹出窗口,我们该怎么做,那里的任何人都解决了我的问题,我不知道如何解决它。
解决方案
使用setInterval()
而不是setTimeout
. 这将在指定的时间段后无限重复。
function alertUser() {
alert("Hello");
}
//This will run on page load
alertUser();
//This will wait 1000ms/1s first and then run the function and will repeat infinitely
setInterval(alertUser(), 1000);
编辑:
要在评论中回答您的问题,只需使用:
window.addEventLister("onclick", alertUser());
推荐阅读
- android - 在使用对讲时通过滑动在标题之间导航
- r - 输出矩阵中每一列的第一个元素的行索引以满足逻辑条件
- python - 将 SQLAlchemy scoped_session 与 Celery 一起使用
- reactjs - 模态不使用 React 路由器和链接关闭
- css - 具有特定属性的后代元素的 css 选择器。
- objective-c - macOS 获取系统中创建连接的通知
- url - PHP中的GET url数据限制
- azure - 如何在 Sprint 中添加任务、问题和错误
- java - 在 Android Studio 中隐藏私人信息的最佳方法是什么?
- c++ - 如何使用 CMake 为其他项目“安装”和使用内部依赖项