How is This Done?

joaquin112

Regular Member
Joined
Apr 4, 2010
Messages
287
Reaction score
224
If you go to this sales page:

http://www.power4home.com/MakeElectricity.php

you will notice that if you hit the back button you are not presented with a popup like all the other CB sites. You are instantly taken to a squeeze page. I think this is a pretty good idea. Can anyone who knows Javascript tell me what's going on and what code he's using?
 
Code:
var is_chrome = /chrome/.test( navigator.userAgent.toLowerCase() );
var is_safari = /safari/.test( navigator.userAgent.toLowerCase() );
var myvar = 0;
var myexit = 0;

if(is_chrome == true || is_safari == true) {
    YUI().use('history', function (Y) {
        var history = new Y.History({
            initialState: {kittens: null,}
          });
          
          history.addValue('kittens');
          
          Y.on('history:change', function (e) {
          if (myvar == 1){
              myexit=1;
              window.location ='/PAGEURL';
              }
          myvar=myvar + 1;
          });    
});
}
else{
YUI().use('history', function (Y) {
        var history = new Y.History({
            initialState: {kittens: 'cat',}
          });
          
          Y.on('history:change', function (e) {
              myexit=1;
              window.location ='/PAGEURL';
          });    
});
}

Just replace "PAGEURL" with the path where you want to redirect your visitors.
 
I've gotta wonder if this is possible when someone tries to close the page as well. Seems like it'd be a nice touch.
 
Back
Top