PHP 页面 - 将弹出窗口/悬停添加到调查邀请中
我想向现有的 PHP 页面添加一个选项,邀请用户参与一项调查 - 我曾在我过去访问过的网站上看到过类似的邀请,但我从未亲自构建过这样的邀请。邀请将是一个悬停的弹出窗口,出现在当前页面的顶部,其中包含进入新窗口/页面的参与选项和简单隐藏邀请的拒绝选项。这项调查只会运行一周,因此我可以在 7 天后轻松删除代码,但它还需要检测用户之前是否访问过此页面,并且不会再次取消邀请。
我假设它将使用 cookie 来检测他们之前是否看过邀请,并使用带有 DIV 的 JavaScript 来显示邀请。我正在寻找任何示例/代码来展示如何在 PHP 页面中执行此操作,以便我可以在我的 PHP 页面上实现此操作。
非常感谢, 史蒂夫
I would like to add an option to an existing PHP page that invites users to participate in a survey - I've seen similar invitations appear on sites that I've visited in the past but have never had to build one myself. The invitation will be a hovering popup that appears on top of the current page with an option to participate which goes to a new window/page and an option to decline which simply hides the invitation. This survey will only run for one week so I can easily remove the code after 7 days but it also needs to detect if the user has previously visited this page and not dislpay the invitation again.
I assume it will use cookies to detect if they've seen the invitation previously and JavaScript with a DIV to display the invitation. I'm looking for any examples/code that shows how to do this in a PHP page so I can implement this on my PHP page.
Many thanks,
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是使用 JavaScript,我使用 jQuery 来执行 JavaScript。因此,您将创建一个 div,因为您希望调查看起来像这样:
然后在 CSS 中放置:
最后对于 jQuery,您可以使用以下代码片段来显示它:
如果您想跟踪是否有人关闭它并让假设您有一个 ID 为 close 的关闭按钮,您可以使用 jQuery 来完成此操作。
在 cookie.php 中,只需:
最后在您的页面上,您只需放置调查消息的 div:
这将允许您仅向拥有 cookie 的人显示消息,并且您可以设置 cookie,而无需离开页。此外,在调查页面上,一旦他们完成调查,您可能会想要设置相同的 cookie,这样他们就不会再这样做了。
The easiest way to do this would to be with JavaScript and I use jQuery to do my javascript. So you would create a div as you would want the survey to look like so:
Then in your CSS put:
Finally for jQuery you can use the following snippet to get it to show:
If you want to keep track if somebody closes it and lets say you have a close button with an ID of close you can do this with jQuery.
and in cookie.php just have:
And finally on your page where you have the div for the survey message just put:
That will allow you to only show the message to people who have the cookie and you can set the cookie without ever leaving the page. Also on the survey page once they've completed it you would probably want to set that same cookie so they don't do it again.