UNDO functionality in jQuery textarea
I am building a small text editor with jQuery. I would like to add 2 buttons with "un-do" (ctrl z) and the opposite (ctrl y) functionality.
Is there any way I can use the built in functionality of windows (ctrl +z, ctrl+y) to get the desired effect, instead of saving everything in stack and implementing it with jQuery? It seems obvious to do so, since ctrl +z and ctrl +y do actually work when using textarea. The only change I need i开发者_如何学Pythons to get the same effect if a user clicks on a button I generate.
Gidi
Javascript is not platform dependent, meaning that no, you can't really depend on typical windows functionality to implement it. That's the bad news. Good news is that windows does it for you already. If you want to create actual buttons to do the same thing, I would do it myself. Have a timer which activates every few seconds once the user begins typing and saves the state of the text. 'Undo' would just restore the previous text state. Just be sure not to let the stack build indefinitely.
You cannot trigger inbuilt browser actions using Javascript. This is for security reasons -- would you want a website accessing the inbuilt functionality of your browser?
You will need to handle all the undo functionality with Javascript, rather than using the browser's functionality.
精彩评论