-1

I have a website and some certain features don't work if the user is using incognito. How can I redirect to another page if incognito is detected. Additionally, how can I display an alert as well?

The following code checks if the user is in incognito. You can also view this at 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>
undo
  • 257
  • 3
  • 19
  • [This article](http://stackoverflow.com/questions/2909367/can-you-determine-if-chrome-is-in-incognito-mode-via-a-script) just checks if the user is in incognito. I need the page to redirect. – undo Jan 24 '15 at 17:11
  • So this question is about doing the redirect? This is simple and can be done by setting `window.location.href` to the desired URL. – aaronk6 Jan 24 '15 at 17:12
  • Unfortunately, I am no good in Javascript :( – undo Jan 24 '15 at 17:13
  • Well, I gave you the solution :-) Where exactly is the problem? – aaronk6 Jan 24 '15 at 17:14
  • how do i apply `window.location.href` and where do I add it? – undo Jan 24 '15 at 17:18

1 Answers1

1

This should be your html file (replace example.com and alert message) :

<!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>
morha13
  • 1,847
  • 3
  • 21
  • 42