drjyvoi734793 2011-06-05 13:20
浏览 25
已采纳

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

  • 写回答

1条回答 默认 最新

  • douao1854 2011-06-05 14:10
    关注

    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:

    <div id="idOfDiv">Style this and do what you normally would</div>
    

    Then in your CSS put:

    #idOfDiv { display:none; }
    

    Finally for jQuery you can use the following snippet to get it to show:

    $("#idOfDiv").fadeIn();  
    //You can add a time in the parenthesis of fadeIn in milliseconds
    //to speed up or slow down the div loading
    

    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.

     $('#close').click(function(){
        $.post('location/of_file/to_set/cookie.php',function(data){
            //If you want to have a confirmation message or something put this here,
            //for after the cookie gets set.
        });
        $('#idOfDiv').fadeOut();
    });
    

    and in cookie.php just have:

    <?php setcookie('noSurvey','true',time()+5000000,'/'); ?>
    

    And finally on your page where you have the div for the survey message just put:

    <?php if(!$_COOKIE['noSurvey']){ /*put div here */ } ?>
    

    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.

    Hope this helps,

    Jeff

    Edit also you will want to work on your acceptance rate if you want more people to answer. That acceptance rate is proportional to the amount of answers you get :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题