1

In my site I want to place a javascript ad code( from Zedo) which is popping up one window for each page visit by the user which is quite nagging.

Ideally what I want is to pop up the ad after user leaves the site or closes the window.

At least I want is to show single pop up in the whole guest session.

I place the ad code before </body> in page.tpl.php but it gets executed for every page.

I'm thinking to make it better by using this logic:

if(time() % 3 == 0)
{
//javascript ad code here
}

At least this will reduce pop up by 3 times.

Are there any better ideas?

3

You can use one cookie, if is the first time to the user enter into your page then create a cookie, when the user change of page you will check if the cookie exists and if exists don't show up the ad.

  • Will adding this cookie checking code affect caching of theme and template files in anyway? – AgA Dec 17 '11 at 7:57
  • No, if handle the cookie using javascript instead of php, with JS doesn't matter what kind of cache are you using in your project. – Gnuget Dec 17 '11 at 8:19
  • The ad code is getting executed by including a js file from the ad server. How do I wrap it with javascript function to get & set cookie? Thanks for your answer. – AgA Dec 17 '11 at 8:29
  • I've created a question for code to include jquery code : drupal.stackexchange.com/questions/17729/… – AgA Dec 17 '11 at 10:45
  • ahh, i answer your question here: drupal.stackexchange.com/a/17762/4362 – Gnuget Dec 17 '11 at 23:27
3

You could set a cookie like this when the user first enters the site:

// php
if(!isset($_COOKIE['ad_zero'])) {
   // display your ad and set the cookie
   setcookie('ad_zero',1);
}

You could also use jQuery Cookie Plugin like this:

if($.cookie('ad_zero') != 1) {
  // display your ad and set the cookie
  $.cookie('ad_zero',1, { expires: 1 });
}
  • Thanks, I need more help with your second example. Before I saw your answer I already asked this question at : drupal.stackexchange.com/questions/17729/… – AgA Dec 17 '11 at 10:44
  • Finally I used this method but I was looking for the following solution and it worked only that for including another cookie plugin in Drupal, I find this method easier. – AgA Dec 18 '11 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.