javascript - 使用 Hopscotch 自动播放游览并在关闭/完成后不再播放吗?

标签 javascript jquery hopscotch

Hopscotch example tour设置参数并调用 hopscotch.startTour(tour); 但关闭“x”和“完成”按钮似乎都无法阻止页面加载后再次播放。

如何实现这一点?

最佳答案

您可以在 onend 函数上使用 localstorage/cookie。

function setCookie(key, value) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
    document.cookie = key + '=' + value + ';path=/' + ';expires=' + expires.toUTCString();
};

function getCookie(key) {
    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    return keyValue ? keyValue[2] : null;
};

var tour = {
    onEnd: function() {
        setCookie("toured", "toured");
    },
    onClose: function() {
        setCookie("toured", "toured");
    }
};

// Initialize tour if it's the user's first time
if (!getCookie("toured")) {
    hopscotch.startTour(tour);
}

关于javascript - 使用 Hopscotch 自动播放游览并在关闭/完成后不再播放吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30810516/

相关文章:

javascript - 如何禁用 Sencha Touch 2 页面转换动画?

javascript - 时刻时区 - 无效日期

javascript - 无法在第二个或第三个删除的动态元素上触发 CK 编辑器 - CkEditor

javascript - D3 js - 添加标签或文本以拖放圆圈

javascript - 跳房子 on 关闭游览功能

javascript - 查找特定结束标记旁边的 HTML 元素

javascript - 获取文本框中过去值之后的文本值

jquery - 将焦点设置到动态加载的 DIV 中的字段

javascript - 从 JSON 属性中删除双引号

jquery - 动态生成内容上的跳房子之旅