先生/女士,
我在索引页面上使用 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代码(以下代码应在正文开放标记之后)
<a id="autoload" class="highslide" href="popup.html" onclick="return hs.htmlExpand(this, {objectType: 'iframe', wrapperClassName: 'draggable-header'})" style="display:none;"></a>
希望你尽快做到需要......
答案 0 :(得分:1)
请参阅此jsFiddle:http://jsfiddle.net/72uny6ba/
HTML code:
<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);
};