Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 14
Registered: ‎02-09-2011
My Device: Not Specified

Clearing cookies

Hi,

 

Is there anyway to clear the cookie of the entire webworks application?

New Developer
Posts: 70
Registered: ‎01-13-2011
My Device: Torch 9800 and Playbook
My Carrier: Rogers

Re: Clearing cookies

Are you referring to a PlayBook or smartphone app? On the playbook, there's no way to clear cookies or cache at this time. However, you may want to consider putting a button in your application that deletes the cookie

 

 

function clearCookie(name, domain, path){
    var domain = domain || document.domain;
    var path = path || "/";
    document.cookie = name + "=; expires=" + +new Date + "; domain=" + domain + "; path=" + path;
};

 

 

Developer
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Clearing cookies

Why would you want to use cookies when you can use HTML5 localStorage?

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Highlighted
Developer
Posts: 598
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Re: Clearing cookies

Here are some resources to help you with HTML5 localStorage:

W3C Spec:
http://dev.w3.org/html5/webstorage/
Sample Code for a simple "To Do"  Application:

The Javascript

This code requires you include jQuery

 

 

      // 'Edit' is ID of wrapper which holds data
      var edit = document.getElementById('edit');

      $(edit).blur(function(){
            localStorage.setItem('todoData', this.innerHTML);
       });

       //when the page loads, retrieve data in localStorage
       if ( localStorage.getItem('todoData') )
       {
           edit.innerHTML = localStorage.getItem('todoData');
       }

       // Target a button, click to clear localStorage
        var btn = document.getElementById('but');

        $(btn).click(function(){
            localStorage.removeItem('todoData');
            location.reload();
        });

 

To clear localStorage idem with key of 'todoData' (or whatever key you set), use:

localStorage.removeItem('key');

 This will have better effect than cookies.

 

The HTML

<!-- include your jquery, and js files in the header -->
...

<!-- set contenteditable property to value of true -->
<ul id="edit" contenteditable="true">
   <li></li>
</ul>

<button id="but">Clear To Do List</button>

 
Hope that helps.


By the way @TheMarco. Screamager looks awesome. Did you use straight HTML5/CSS, WebWorks to develop?