you can do it with timestamps.
There is the "browser-object" which can detect if your window is unfocused.
If you are interested in a full idle game script made with construct 2, here you can buy it very cheap:
There are all these functions included (unfocused window, offline mode...)
Here the link to the game how it looks like: