简体   繁体   English

弹出新标签页的首次访问?

[英]New tab pop-up first visit?

I want to show an informative little message in a new tab the first time someone enters my website. 有人第一次进入我的网站时,我想在新标签中显示一条信息性的小消息。 Thing is though, I can't make it work. 事实是,我无法使其正常工作。 Here's some code: 这是一些代码:

<html>
    <?php
        $cookie_name = "visited";
        $cookie_value = "1";
        if(!isset($_COOKIE[$cookie_name])) {    

            setcookie($cookie_name, $cookie_value, time()+60*60*24*365);

            echo "
                <script type='text/javascript'>
                    function PopUp() {
                        window.open('http://example.com/information', '_blank');
                    }
                    PopUp();
                </script>
            ";
        }
    ?>

No cookie is set, but the pop-up keeps showing up every time I refresh the page. 没有设置cookie,但是每次我刷新页面时都会弹出窗口。 Not sure how to go about this. 不知道如何去做。

setcookie() must be called before any other browser output, ie before your <html> tag. 必须在任何其他浏览器输出之前(即在您的<html>标记之前setcookie()调用setcookie() otherwhise browser reject it. 其他浏览器拒绝它。

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

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