In Angular, how to prevent a user from changing from the current tab?

735 Views Asked by At

I have an exam application where we would like to prevent users from changing tabs or opening new tabs during the exam as a security measure. Can you suggest ways to achieve the same?

3

There are 3 best solutions below

2
On

I don't think its possible and pupils could have other web browsers installed anyway or use a smartphone, a tablet, another computer... to browse the web.

0
On

I don't think is possible to avoid open new tabs or windows. However, you can check if your app has the user's focus.

There is a detailed answer about this topic and browser's compatibility here Is there a way to detect if a browser window is not currently active?

0
On

You could achieve this by creating a desktop application that hosts a browser. Not as complex as it might seem but it requires a different tech stack. Furthermore, it obviously requires installation on clients which might not be feasible in your use case. One option out of many would be:

  • Create a WPF application
  • Force it to stay on top, i.e. WPF always on top
  • Add Chromium as webbrowser: Chromium
  • Implement some custom behavior, such as opening the test page on startup, etc.

Assuming the tech stack is known I would estimate it can be done within a couple of hours including testing. The solution also gives you a bit of additional control, i.e. over browser caching which you could disable...