您好,我有此代码可用于重定向回 重定向用户离开您的网站-JavaScript后退按钮黑客攻击
<?php
$javascript = <<<DOC
<script>
var ref = document.referrer;
var siteurl = "YOUR URL HERE";//if you have www, then use www. http://www.yoursite.com
if (ref.indexOf(siteurl)!= -1){
}
else{
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/auth");
history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", function() {
if(location.hash === "#!/auth") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
location.replace("http://www.blackhatworld.com/");
},0);
}
}, false);
}(window, location));
}
</script>
DOC;
echo $javascript;
?>
我想为其添加一个计数器,该计数器仅在单击3次后才能重定向。 怎么做?
答案 0 :(得分:0)
尝试以下javascript代码:
<button id="button">Click Back 3 Times </button>
<script>
var counter = 0;
$("#button").click(function () {
counter++;
if (counter == 3) {
window.history.back();
}
});
</script>
答案 1 :(得分:0)
此代码也有效,但我需要添加计数器 此代码适用于重定向返回重定向用户离开您的网站-Java脚本后退按钮入侵:
<script>
// managage back button click (and backspace)
var count = 0; // needed for safari
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("back", null, null);
window.onpopstate = function () {
history.pushState('back', null, null);
if(count == 1){window.location = 'http://google.co.il';}
};
}
}
setTimeout(function(){count = 1;},200);
</script>
答案 2 :(得分:0)
第三次单击浏览器后退按钮后正在寻找使重定向到页面的代码...前2次单击应保留在页面上