B
B
BonBon Slick2016-07-27 21:28:36
Regular Expressions
BonBon Slick, 2016-07-27 21:28:36

How to delete cookies on tab close?

I use this jquery code, in theory, without an expiration date, they should be deleted by themselves when the window is closed (not following the site links)

// если куки нет, то создаем 
    if( !$.cookie("first_visit") ){ 
          // Creating and saving cookies
          $.cookie("first_visit", "Visited!", { path: '/'  });
          // Redirect to... ( тут ссылка для перенаправления ) 
          window.location.href =  shop_url;
        }

Here, but when the window is closed, the cookies remain, therefore, there are no redirects ;(

P.S.
Here is the whole code for those who are interested:
jQuery(document).ready(function($) {
  var $ = jQuery;

  function sreen_width_check(){
// Make variables
var main_page_url = 'http://piwo.com.ua/';
var shop_url = 'http://piwo.com.ua/shop/';
var curr_page_url = $(location).attr('href');

var screen_width = $(window).width();

// Requirements for redirection
if( curr_page_url === main_page_url ){
  if ( screen_width <= 1280 ){
    if( !$.cookie("first_visit") ){
          // Creating and saving cookies
          $.cookie("first_visit", "Visited!", { path: '/'  });
          // Redirect to...
          window.location.href = shop_url;

        }
      }
    }

  };

  sreen_width_check();

});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Lebedev, 2016-07-27
@BonBonSlick

Tab close event , on which you need to hang your handler with deleting cookies :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question