Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Ctrl+z & Ctrl+y keypress on button click

I have provided two separates button for Ctrl+z and Ctrl+y. I want the Ctrl+z and Ctrl+y functionality to be performed on the click of a button.

To achieve this, I am trying to trigger Ctrl+z and Ctrl+y on button click but they are not getting triggered.

The code I have written so far:

case "undo":
    var press = jQuery.Event("onkeydown");
    press.ctrlKey = true;
    press.keyCode = 90;
    jQuery(".excellentableEditSpread").trigger(press);
    break;

case "redo":
    var press = jQuery.Event("onkeydown");
    press.ctrlKey = true;
    press.keyCode = 89;
    jQuery(".excellentableEditSpread").trigger(press);
    break;
like image 265
Akanksha Avatar asked Dec 03 '15 10:12

Akanksha


1 Answers

You can try this:

function doUndo(){
  document.execCommand('undo', false, null);
}

function doRedo(){
  document.execCommand('redo', false, null);
}
like image 180
parismiguel Avatar answered Nov 07 '22 06:11

parismiguel