0

先生/女士,

我已经使用Highslide脚本在索引页面上自动弹出。因此,当用户打开网站时,应该可以看到一个弹出窗口,其中包含自定义消息。但我希望它只对用户可见一次,如果用户关闭弹出窗口,它不应该再次可见,直到浏览器会话处于活动状态。自动弹出代码工作正常,但我希望它只显示一次。

我使用了下面的代码:(下面的代码应该在head标签之间)

    <!---For HighSlide Auto Popup--->
          <script type="text/javascript" src="highslide/highslide-full.js"></script>
            <link rel="stylesheet" type="text/css" href="highslide/highslide.css">
          <script type='text/javascript'>//<![CDATA[
              // automatically open a link to a HTML page
              hs.graphicsDir = 'highslide/graphics/';
              hs.align = 'center';
              hs.outlineType = 'rounded-white';
              hs.dimmingOpacity = 0.75;

              hs.addEventListener(window, "load", function() {
              // click the element virtually:
              document.getElementById("autoload").onclick();
              });

              hs.registerOverlay({
             html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
             position: 'top right',
             fade: 2 // fading the semi-transparent overlay looks bad in IE
              });
              //]]>
            </script>     
          <!---Ends Here--->

HTML 代码:(下面的代码应该在body open tag之后)

    <a id="autoload" class="highslide" href="popup.html" onclick="return hs.htmlExpand(this, {objectType: 'iframe', wrapperClassName: 'draggable-header'})" style="display:none;"></a>

希望你应该尽快做需要....

4

1 回答 1

1

看到这个jsFiddle:http: //jsfiddle.net/72uny6ba/

HTML 代码:

<a id="autoload" class="highslide" style="display: none;" href="https://fiddle.jshell.net/roadrash/7AHX9/show/light/" onclick="return hs.htmlExpand(this, {objectType: 'iframe', wrapperClassName: 'draggable-header'})">Autoloaded popup</a>


用于 cookie 和自动加载的 JavaScript:

// cookie
    function bakecookie(name, value) {
       var argv = bakecookie.arguments;
       var argc = bakecookie.arguments.length;
       var daysgood = (argc > 2) ? argv[2] : null;
       var path = (argc > 3) ? argv[3] : "/";
       var domain = (argc > 4) ? argv[4] : null;
       var secure = (argc > 5) ? argv[5] : false;
       var expires = new Date();
       expires.setDate (expires.getDate()+daysgood);
       document.cookie = name + "=" + escape (value) +((daysgood == null) ? "" : ("; expires=" + expires.toGMTString())) +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain)) +((secure == true) ? "; secure" : "");
    }

    function eatcookie(name) {
       var arg = name + "=";
       var alen = arg.length;
       var clen = document.cookie.length;
       var i = 0;
       while (i < clen) {
          var j = i + alen;
          if (document.cookie.substring(i, j) == arg) {return eatcookieval (j);}
          i = document.cookie.indexOf(" ", i) + 1;
          if (i == 0) {break;}
       }
       return null;
    }

    function eatcookieval(offset){
       var endstr=document.cookie.indexOf(";",offset);
       if (endstr == -1) {endstr = document.cookie.length;}
       return unescape(document.cookie.substring(offset,endstr));
    } 

// autoload popup
hs.addEventListener(window, "load", function () {
    // click the element virtually:
    if (!eatcookie('YouveSeenOurNewSite')) {
        document.getElementById("autoload").onclick();
    }
});

// set the cookie
hs.Expander.prototype.onAfterExpand = function (sender) {
    bakecookie('YouveSeenOurNewSite', true, 365);
};
于 2015-03-05T14:14:36.710 回答