press Ctrl+Shift+Del outof firefox extension
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( 'keypr开发者_高级运维ess', 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" the combination Ctrl+Shift+Del
so..any ideas? see mistakes?
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.
How about opening the popup that Ctrl+Shift+Del opens?
Edit: It's chrome://browser/content/sanitize.xul
. You may also want to have a look at chrome://browser/content/sanitize.js
.
精彩评论