I need to fire the Ctrl+R, Ctrl+A, Ctrl+Q events when a user clicks on a button.
I was working on the following code:
$(document).ready(function () {
$('#Button1').click(function () {
var evt = $.Event("keypress");
evt.keyCode = 81;
evt.ctrlKey = true;
evt.shiftKey = true;
$(document).trigger(evt);
});
});
You can't simulate browser control keys, but you can simulate their effects.
Ctrl-R refreshes.
function refresh() {
location.reload(true);
}
Ctrl-A selects everything. Code is from here.
function selectAll() {
var e = document.getElementsByTagName('body')[0];
var r = document.createRange(); r.selectNodeContents(e);
var s = window.getSelection();
s.removeAllRanges();
s.addRange(r);
}
I am not sure what Ctrl-Q is supposed to do; if it quits the browser, that one isn't possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With