I am a fresher and working on a Coupons website.
I want to know, when a window loads, how to press ctrl+c itself.
Ctrl+c keys should be pressed automatically right after the loading of window.
I am a fresher and working on a Coupons website.
I want to know, when a window loads, how to press ctrl+c itself.
Ctrl+c keys should be pressed automatically right after the loading of window.
Since you're using jQuery you could do it using jQuery.Event
:
var e = jQuery.Event("keydown");
e.which = 67; // 'C' key code value
e.ctrlKey = true;
$("body").trigger(e);
Hope this helps.
jQuery Solution
$(function(){ //Ready function
//Event that catch the Ctrl+C press (Just for test)
$("body").keydown(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 67) {
if (e.ctrlKey) {
alert("Ctrl+C was pressed!!");
}
}
});
//Event that trigger the 'Ctrl+C'
var e = jQuery.Event("keydown");
e.which = 67; // 'C' key code value
e.ctrlKey = true;
$("body").trigger(e);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Javascript Solution
document.addEventListener('keydown', function (e) {
if (event.altKey && event.key === 'n')
{
document.querySelectorAll('._180aQody._254QuS8h')[0].click();
}
});
document.querySelector('._180aQody._254QuS8h').addEventListener('click', function (e) {
alert("Alt+n was pressed!!");
});
var ev = new KeyboardEvent('keydown', {bubbles: true, altKey: true, key: "n"});
document.querySelectorAll('._180aQody._254QuS8h')[0].dispatchEvent(ev);
<button class='_180aQody _254QuS8h'>CLick me using Alt+n</button>