如果处于隐身状态,则重定向并显示警报

时间:2015-01-24 17:08:15

标签: javascript html google-chrome incognito-mode

我有一个网站,如果用户使用隐身功能,某些功能无效。如果检测到隐身,我该如何重定向到另一个页面。另外,我该如何显示警报?

以下代码检查用户是否处于隐身状态。您也可以在http://rahul2001.com/inco.html

查看此信息
<!DOCTYPE html>
<html>
<head>

  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Inco-Check</title>

<script type='text/javascript'>
//<![CDATA[ 
window.onload=function(){
function main() {
  var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
  if (!fs) {
    result.textContent = "check failed?";
    return;
  }
  fs(window.TEMPORARY, 100, function(fs) {
    result.textContent = "Negitive: You aren't using Incognito";
  }, function(err) {
    result.textContent = "Positive: You're using Incognito";
  });
}
main();

}//]]>  

</script>
</head>
<body>

  <h2>This webpage checks if you are in <i>Incognito</i> mode</h2>
  <hr>
<h3>Result</h3>
<h4>
<div id="result"></div>
</h4>
  <hr>
  <hr>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

这应该是你的html文件(替换example.com和警告消息):

<!DOCTYPE html>
<html>
<head>

  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Inco-Check</title>

<script type='text/javascript'>
//<![CDATA[ 
window.onload=function(){
function main() {
  var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
  if (!fs) {
    result.textContent = "check failed?";
    return;
  }
  fs(window.TEMPORARY, 100, function(fs) {
    result.textContent = "Negitive: You aren't using Incognito";
  }, function(err) {
    window.location.href = "http://www.expmle.com";
    alert("This is an alert!");
  });
}
main();

}//]]>  

</script>
</head>
<body>

  <h2>This webpage checks if you are in <i>Incognito</i> mode</h2>
  <hr>
<h3>Result</h3>
<h4>
<div id="result"></div>
</h4>
  <hr>
  <hr>
</body>
</html>