-1

I'm have no basic on jQuery, so really need help with this one.

$(document).ready(function(){
        alert('Warning!!');
        document.write('prohibited);});

the code above is not made by me, but from my understanding is when the document is ready or finish load up it will call the function, and display window message and write on the document.

what i want to ask is how to combine it with keypress, let say when someone try to view source, so when the document is ready, and someone press ctrl+u then it will call the function, then display the alert, and do the document.write

Thank you :)

  • Possible duplicate of [jquery: keypress, ctrl+c (or some combo like that)](https://stackoverflow.com/questions/4604057/jquery-keypress-ctrlc-or-some-combo-like-that) – Vivek Athalye Aug 22 '17 at 06:49
  • i'm sorry if this a duplicate, because maybe i search with a wrong keyword before when i try to find answer to this problem, but thanks btw, i will try to read the discussion – dycodingcoda Aug 22 '17 at 07:00

1 Answers1

0

You can write key press event this way:

$(document).on("KeyPress",function(event){
if(event.which == 55 && cntrlIsPressed)
{
alert('Do Something');
document.write('prohibited');
}        
});
  • i try it but it doesn't call the function, alert and document.write at all – dycodingcoda Aug 22 '17 at 07:05
  • still doesn't work, crtl+u function like normal. for the `function()` i write in ext file, so what i intend the script to do is when the document is ready, it will run the `function()` and popup `alert` and do the `document.write` if ctrl+u is pressed, – dycodingcoda Aug 22 '17 at 07:17