Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Is there any way to detect Ctrl + S?

I need to write a page which does not allow the user to see the code. To catch the context menu open I want to use the JS event. To catch web-console open I want to use this: https://sindresorhus.com/devtools-detect/ and close the page. How to catch saving? Is it enough to catch Ctrl+S?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No, trapping ctrl + s will only solve the case where the user uses a keyboard shortcut (be sure to remember it's cmd+s for Macs). They will still get the save webpage dialog if they use the File Menu or the context menu's "Save As" action. I have never heard of a way to trap those.

You will never be able to prevent the user from seeing your code, if the browser can download and execute it, the user can see it, whether through curl, a packet sniffer or DevTools.

The best you can do is obfuscate your code, which anyone with enough skills will be able to turn in to non-obfuscated code.

about 4 years ago · Juan Pablo Isaza Report

0

We can listen for keydown. If the ctrlKey and S key are being pressed, do the work. The preventDefault is preventing the save page dialog from opening up.

document.addEventListener('keydown', (e) => {
  if (e.ctrlKey && e.key === 's') {
    e.preventDefault();
    console.log('pressing ctrl+s')
  }
});

But preventing a user from seeing your code? That's a different story. We can detect Ctrl+S, but not prevent someone from seeing your code.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!