2

I want to know that when I used multiples types of software on my computer, the browser can detect the others software is running or to?

And also can the browser handle that the browser is running in the background when I use another software.

Or when I used alt+tab to switch software, Is it possible for the browser to detect.

Mijanur Rahman
  • 1,094
  • 1
  • 11
  • 20
  • The browser can certainly detect this. Why do you care? Are you asking whether javascript from inside a website displayed in the browser can detect this? – Bergi Jul 09 '21 at 18:14
  • The browser can detect this. Browser extensions can also detect this with basic permissions. Additionally, pages can listen to certain DOM events to detect when they are no longer in focus. This is not an exhaustive list, but may give you some hints. – zr0gravity7 Jul 09 '21 at 18:26
  • Can browser detect when switching to another software from the browser? @Bergi – Mijanur Rahman Jul 10 '21 at 02:23
  • Can I handle extension from raw JS code? @zr0gravity7 – Mijanur Rahman Jul 10 '21 at 02:25
  • 1
    @MijanurRahman Again, what do you mean by "from the browser"? A browser is just an application like any other, and yes, the OS (window manager) provides a way to detect that. But you're not implementing a browser, are you? What are you trying to do, what is your [actual problem](https://meta.stackexchange.com/q/66377)? – Bergi Jul 10 '21 at 02:36
  • Basically, I want to know when a user switched from the browser to any other software like `VLC Media player. Is the browser can detect this? @Bergi – Mijanur Rahman Jul 10 '21 at 03:20
  • I am trying to develop an `Exam Management System` where I want to know the user is passed away from the browser or not when giving the question answers. – Mijanur Rahman Jul 10 '21 at 03:24
  • Do you have any other idea to detect users is left the browser? @Bergi, please. – Mijanur Rahman Jul 10 '21 at 04:03

1 Answers1

2

You can make use of Page Visibility API:

var visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
  visibilityChange = "visibilitychange";
} else if (typeof document.msHidden !== "undefined") {
  visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
  visibilityChange = "webkitvisibilitychange";
}
//^different browsers^

document.addEventListener(visibilityChange, function(){
  console.log("Visibility changed at "+new Date());
}, false);
Spectric
  • 30,714
  • 6
  • 20
  • 43