popup javascript每次访问一次

时间:2016-07-02 01:11:34

标签: javascript jquery

在智能手机中使用此代码JavaScript弹出工作

<script type="text/javascript">
var shouldOpenWindow = true;
function open_on_click(url,name) {
     if( /Android|iPhone|BlackBerry/i.test(navigator.userAgent) ) {
      window.open('market://details?id=picture.profile.logo.football','picture profile logo football');
      // if you want that only on first click the popup must be opened, and not on any subsequent clicks, then do this
      shouldOpenWindow = !shouldOpenWindow;

   }
}
</script>
<body onclick="open_on_click()">

我想在每个新会话期间使页面出现 例如,每小时一次

1 个答案:

答案 0 :(得分:0)

window.localStorage - 存储没有过期日期的数据

// Store
localStorage.setItem("lastname", "Smith");

// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");

因此,只需设置一个变量,该变量将保留用户上次访问该网站的时间,然后相应地显示或跳过弹出窗口。

您需要检查目标设备是否支持它,但是一些较旧的移动浏览器可能仍然存在问题。

if (typeof(Storage) !== "undefined") {
    // Code for localStorage/sessionStorage.
} else {
    // Sorry! No Web Storage support..
}

来源http://www.w3schools.com/html/html5_webstorage.asp

相关问题