Javascript 如果处于匿名状态,则重定向并显示警报
我有一个网站,如果用户使用隐姓埋名,某些功能将无法工作。如果检测到匿名,我如何重定向到另一个页面。此外,如何显示警报 下面的代码检查用户是否处于匿名状态。您也可以在Javascript 如果处于匿名状态,则重定向并显示警报,javascript,html,google-chrome,incognito-mode,Javascript,Html,Google Chrome,Incognito Mode,我有一个网站,如果用户使用隐姓埋名,某些功能将无法工作。如果检测到匿名,我如何重定向到另一个页面。此外,如何显示警报 下面的代码检查用户是否处于匿名状态。您也可以在 国际贸易支票 // 此网页检查您是否处于匿名模式 结果 这应该是您的html文件(替换example.com和警报消息): 国际贸易支票 // 此网页检查您是否处于匿名模式 结果 只需检查用户是否隐姓埋名即可。我需要页面重定向。所以这个问题是关于重定向的?这很简单,可以通过将window.location.h
国际贸易支票
//
此网页检查您是否处于匿名模式
结果
这应该是您的html文件(替换example.com和警报消息):
国际贸易支票
//
此网页检查您是否处于匿名模式
结果
只需检查用户是否隐姓埋名即可。我需要页面重定向。所以这个问题是关于重定向的?这很简单,可以通过将window.location.href
设置为所需的URL来实现。不幸的是,我不擅长Javascript:(好吧,我给了你解决方案:-)问题到底在哪里?我如何应用window.location.href
以及在哪里添加它?它可以工作!!非常感谢@RahulBasu请将其标记为答案(按我解决方案旁边的V键)哈哈哈,完成了。再次感谢…@RahulBasu欢迎您:)
<!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>
<!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>