弹出窗口不适用于实时主机,但适用于本地主机

时间:2020-10-04 17:20:08

标签: javascript jquery popup

我创建了一个弹出窗口,该窗口仅对我的网站的第一位访问者可见。它实际上可以在本地主机上正常运行,但不能在实时主机上运行。此问题的问题是什么?任何人都可以帮助我解决此问题。这对我来说非常重要,因为我不能仅为此问题发布网站。

index.html

<html>
<head>
        <style>
body { margin-top: 0; }

#container {
  max-width: 1000px;
  margin: 0 auto;
  background: #EEE;
}

h1,
p { padding: 1em 1em; }

#fvpp-blackout {
  display: none;
  z-index: 499;
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: #000;
  opacity: 0.5;
}

#my-welcome-message {
  display: none;
  z-index: 500;
  position: fixed;
  width: 36%;
  left: 30%;
  top: 20%;
  padding: 20px 2%;
  font-family: Calibri, Arial, sans-serif;
  background: #FFF;
}

#fvpp-close {
  position: absolute;
  top: 10px;
  right: 20px;
  cursor: pointer;
}

#fvpp-dialog h2 {
  font-size: 2em;
  margin: 0;
}

#fvpp-dialog p { margin: 0; }
</style>
        </head>

        <body>
<div id="my-welcome-message">
          <h2>Welcome to my site</h2>
          <p>Hello, welcome to my website.</p>
        </div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script src="jquery.firstVisitPopup.js"></script> 
<script>
            $(function () {
                $('#my-welcome-message').firstVisitPopup({
                    cookieName : 'homepage',
                    showAgainSelector: '#show-message'
                });
            });
        </script><script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-36251023-1']);
  _gaq.push(['_setDomainName', 'jqueryscript.net']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>
</html>

jquery.firstVisitPopup.js

(function ($) {

    'use strict';

    $.fn.firstVisitPopup = function (settings) {

        var $body = $('body');
        var $dialog = $(this);
        var $blackout;
        var setCookie = function (name, value) {
            var date = new Date(),
                expires = 'expires=';
            date.setTime(date.getTime() + 31536000000);
            expires += date.toGMTString();
            document.cookie = name + '=' + value + '; ' + expires + '; path=/';
        }
        var getCookie = function (name) {
            var allCookies = document.cookie.split(';'),
                cookieCounter = 0,
                currentCookie = '';
            for (cookieCounter = 0; cookieCounter < allCookies.length; cookieCounter++) {
                currentCookie = allCookies[cookieCounter];
                while (currentCookie.charAt(0) === ' ') {
                    currentCookie = currentCookie.substring(1, currentCookie.length);
                }
                if (currentCookie.indexOf(name + '=') === 0) {
                    return currentCookie.substring(name.length + 1, currentCookie.length);
                }
            }
            return false;
        }
        var showMessage = function () {
            $blackout.show();
            $dialog.show();
        }
        var hideMessage = function () {
            $blackout.hide();
            $dialog.hide();
            setCookie('fvpp' + settings.cookieName, 'true');
        }

        $body.append('<div id="fvpp-blackout"></div>');
        $dialog.append('<a id="fvpp-close">&#10006;</a>');
        $blackout = $('#fvpp-blackout');

        if (getCookie('fvpp' + settings.cookieName)) {
            hideMessage();
        } else {
            showMessage();
        }

        $(settings.showAgainSelector).on('click', showMessage);
        $body.on('click', '#fvpp-blackout, #fvpp-close', hideMessage);

    };

})(jQuery);

jquery.firstVisitPopup.min.js

! function(e) {
    "use strict";
    e.fn.firstVisitPopup = function(t) {
        var i, o = e("body"),
            n = e(this),
            c = function(e, t) {
                var i = new Date,
                    o = "expires=";
                i.setTime(i.getTime() + 31536e6), o += i.toGMTString(), document.cookie = e + "=" + t + "; " + o + "; path=/"
            },
            p = function(e) {
                var t = document.cookie.split(";"),
                    i = 0,
                    o = "";
                for (i = 0; i < t.length; i++) {
                    for (o = t[i];
                        " " === o.charAt(0);) o = o.substring(1, o.length);
                    if (0 === o.indexOf(e + "=")) return o.substring(e.length + 1, o.length)
                }
                return !1
            },
            f = function() {
                i.show(), n.show()
            },
            r = function() {
                i.hide(), n.hide(), c("fvpp" + t.cookieName, "true")
            };
        o.append('<div id="fvpp-blackout"></div>'), n.append('<a id="fvpp-close">&#10006;</a>'), i = e("#fvpp-blackout"), p("fvpp" + t.cookieName) ? r() : f(), e(t.showAgainSelector).on("click", f), o.on("click", "#fvpp-blackout, #fvpp-close", r)
    }
}(jQuery);

请任何人帮助我解决此问题。

0 个答案:

没有答案