问题描述
样式
HTML
Javascript
弹出窗口设置为自动启动,用户可以退出.我还想在网站上放置一个链接,以根据命令显示弹出窗口.我试过了:
The popup is set to launch automatically and the user can exit. I want to also put a link on the site to make the popup show on command. I have tried:
并显示弹出窗口,但似乎无法正常工作.
当我点击链接时,启动这个所谓的邪恶弹出窗口的正确形式是什么?
and the popup is shown but doesn't seem to work properly.
What is the correct form to launch this so called evil popup when I click on a link?
推荐答案
我最近从一个客户那里得到了这段代码(他们从 Mailchimp.com 复制的)
I recently got this code from a client (that they copied from Mailchimp.com)
这是 Evil-PopUp 代码,通过将其添加到您的网站,您会在页面加载时获得简报注册的弹出窗口(模式窗口).
This is the Evil-PopUp Code and by adding this to your site you get the popup (modal window) for newsletter-signup when the page loads.
我的客户希望此弹出窗口仅在单击立即注册"按钮时显示.所以这就是我所做的.
My client wanted this popup to show only when a "Sign up now" button was clicked. So this is what I did.
首先我将第一个脚本按原样添加到站点:
First I added the first script as is to the site:
第二个我写了一个函数来运行第二个脚本中的代码,并将一个点击事件附加到一个ID为#open-popup的按钮
Second I wrote a function that runs the code from the second script and attached a click event to a button with id #open-popup
我以为是这样,但发现 Mailchimp 脚本在用户第一次关闭弹出窗口后添加了一个名为MCEvilPopupClosed"的会话 cookie.如果设置了该 cookie,您将无法再次打开弹出窗口(因为此弹出窗口仅在用户进入页面时显示一次).
I thought this was it, but found out that the Mailchimp script adds a session cookie called "MCEvilPopupClosed" after the user has closed the popup for the first time. If that cookie is set you can not open the popup again (since this popup was only meant to be shown once when the user enters the page).
解决方案是添加此代码以在页面加载时以及每次单击模式关闭按钮时删除 cookie(需要 jQuery,但如果您当然可以用 vanilla Javascript 编写喜欢).根据新评论,cookie 键已从 MCEvilPopupClosed
The solution to that was adding this code to delete the cookie when the page loads and also each time the modal close button is clicked (requires jQuery but can of course be written in vanilla Javascript if you like). According to new comments the cookie key has changed to MCPopupClosed from MCEvilPopupClosed
现在...用户可以根据自己的喜好打开和关闭 Evil Popup.
Now... the user can open and close the Evil Popup as s/he likes.
您可以使用下面@rok-jakli 的解决方案,而不是使用我的代码来清除 cookie.它比我的更好/更简单.休息应该是一样的.
Instead of using my code to clear the cookies you could use the solution from @rok-jakli below. It's better/simpler then mine. Rest should be the same.
这篇关于启动 Mailchimp 邪恶弹出 onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!