Reputation: 9
I want to press Ctrl+L keys using JavaScript always when my website are loaded, my code is:
$(document).ready(function() {
var e = $.Event("keydown");
e.keyCode = 76;
e.ctrlKey = true;
$('body').trigger(e);
});
but it doesn't work, please help - result: I want highligt address bar always when my website are loaded.
Upvotes: -1
Views: 575
Reputation: 181
To manipulate user action you can use chrome devtools protocol There are some browser automation and testing frameworks which provides high-level api to easily achieve what you need.
Upvotes: 0
Reputation: 83
you can use something like this with jquery
$("body").keydown(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 67) {
if (e.ctrlKey) {
alert("Ctrl+C was pressed!!");
}
}
});
var e = jQuery.Event("keydown");
e.which = 67; // 'C' key code value
e.ctrlKey = true;
$("body").trigger(e);
Upvotes: -4
Reputation: 23174
This is just not possible, this feature is blocked by any decent browser since a long time ago.
As noticed in comments, that would be a catastrophic security weakness for any user.
(access to url toolbar would allow stealing history easily, and even opening some files on the client's computer, and going to dubious sites where worse could happen)
Upvotes: 4