views:

121

answers:

2

So, i need to press Ctrl+Shift+Del in a program way. I want my extension to press Ctrl+Shift+Del and then press 'Enter' (to clean all history,cookies,cache and so on). i do next:

var e=document.createEvent('KeyboardEvent');
e.initKeyEvent( 'keypress', true, true, window, true, false, true, false, 46, 0);
document.dispatchEvent(e);

According to how i understand, this code has to emulate pressing Ctrl+Shift+Del but nothing happens...document.dispatchEvent(e) happens but the window that is called by pressing Ctrl+Shift+Del doesn't appear..why? p.s.\i know about Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager).removeAll(); but it's not suitable in my situashion. i do definetly need to "press" these Ctrl+Shit+Del so..any ideas? see mistakes?

+2  A: 

Emulating key press events to start a native function of the browser sounds like a bad, and probably unnecessary, idea.

Why not check out other extensions that clear the cache/history like this one and check out its source code to see how it's done.

Pekka
see...the problem is that since gecko 1.9 according to developer.mozilla.org/en/nsICookieManager i'm not able to use this:Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager).removeAll();and i need to clear not only cache, but cookies too.and i got no idea how to solve this problem in another way...
lazybob
I see, that's indeed a pickle. Still, keypresses are very unlikely to get you anywhere. There must be some sort of documentation how to clear cookies in a current generation Firefox. Maybe it's worth setting up another question to that effect.
Pekka
A: 

How about opening the popup that Ctrl+Shift+Delete opens?

Edit: It's chrome://browser/content/sanitize.xul. You may also want to have a look at chrome://browser/content/sanitize.js.

Eli Grey
yeh.that's might work!thanx, man.
lazybob
Then can you accept my answer?
Eli Grey