Question

I am trying to figure out how to hide an element to not show again if a user clicks the dismiss button. Basically it is just a drop down with promotional information. If the user clicks dismiss, I do not want this element to show to that user ever again.

I would like it to function like the banner seen here http://codecanyon.net/

Is there a way to do this? I tried Googling this answer but could not really find this example. I am assuming this needs to be achieved with cookies. Also, if that is the case, would that cause any issues with SSL Encrypted pages?

Update: What about just setting a cookie that would expire after so many days?

Here is my code:

   <div id="promotional-banner">
      <div id="promotional-wrapper">
          <div id="promotional-container">
              <p class="left"><img src="<?php echo Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL); ?>media/wysiwyg/infortis/fortis/custom/rewards.png" alt="Earn Rewards" title="Earn Rewards" /> Earn reward points every time you shop at WeePumpkin.com</p>
              <div class="right close-button"><span>X</span> Dismiss</div>
              <div class="clear"></div>
          </div>
      </div>
   </div>

   <script type="text/javascript">
     $$ = jQuery;
     $$(document).ready( function() {
        if ($$("#promotional-banner").is(":hidden")) {
        $$("#promotional-banner").delay("1000").fadeIn();
        }

     $$("div.close-button").click(function(){
        $$("#promotional-banner").delay("slow").fadeOut();
     });
     });
   </script>
Was it helpful?

Solution

If you mean "forever forever", like when they leave the page and come back, you will need to incorporate a server side technology.

If you have users who aren't registered, you could use PHP (or similar) to capture their IP and mark that IP with a flag. The flags initial state would be 'show' or similar. Once they have clicked dismiss, do a quick jQuery ajax request to your server marking the flag as 'hide'.

Obviously if they changed their IP you're info would be out of date.

You could also use cookies as a solution, but if they cleared their cookies it would be lost.

OTHER TIPS

you could achieve this using a combination of backend and front end solutions. Basically when a user is registered, his username is registered against a backend flag (in database) like isPromotionsAllowed. When the user is initially registered, this flag has to be set to true. When he accesses the application by logging again, the promotional content like banners will be displayed to him, if this flag in the db is set to true. When he clicks "dismiss", the backend database field will be updated to false and hence, he will not see the content any longer.

To improve the user experience,this flag can be extended to cookies as well.When he clicks dismiss, a cookie can be saved consisting the flag so that we can save the extra round trips to the server and back to check if the promotional matters are to be displayed or not. This is a conditional enhancement that we can implement on top of the basic solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top