How to detect desktop is locked in javascript - javascript

A simple question that I just can't find an answer for. I want to stop a periodic AJAX call when the user has wandered away and locked their PC. I don't need it to be every OS compatible or every browser (Chrome and IE would be good).
setInterval just doesn't seem to stop when locked and AJAX is also not prevented. The visibilitychange event seems to think that the tab is visible unless you switch to another tab.
I have stated javascript, but I only care that it can be done within the browser without asking the user.
Edge does seem to indicate it is hidden when locked, so I'm ok with that browser.
Thanks

You can use the Idle.js library to detect if the user is looking away from the browser window or is inactive (his input devices are inactive).
Whatever the case, there's not a reliable way to get the OS or the screen saver state from the browser

In your javascript it is not possible to detect if the OS UI has locked. The browser sand box prevents this kind of access to OS resources for security reasons. You would need to write a browser plugin to do this.

Related

open Chrome console when DOM ready and set viewport

I am wondering if there is any way I can open Chrome console when the webpage is firstly loaded and set the viewport to a specific device (iPhone X), through a JavaScript code.
I had to do a test where I should only work on iPhone X viewport so I thought was nice if they can already see the console opened with the interested viewport active so they are going to check straight away my work instead of clicking cmd+alt+j and then set toggle device toolbar
Thanks
I don't know this to be true, but I'm guessing that might not be possible because it would infringe on the sandboxing principles that Chrome tabs are based on. You are asking for system level control of the Chrome Browser UI, and there's a lot of effort put into not letting JS code do that because of malicious intent.
You could try using Electron to build an App that does this for you, however that may still have the sandbox boundary concern.
EDIT - You may also look into the Chrome extension architecture. It allows you to implement code outside of the sandbox boundaries. I'm not entirely hopeful that this would work, but it I do know that extensions allow you to control most of interface.

Safest way to break Flash focus?

The gist: What's the best way to escape a Flash object's focus on a webpage?
Context:
I have a hotkey listener (an AutoHotKey script) running in my tray. If the script detects the command Alt+Shift+F6 while I am clicked into a Flash object on a webpage, it activates and sends key combinations to Flash to pull certain data logs. After this process completes, I want to call up a JavaScript file on that same browser tab that requests additional information from the user - basically, a tiny UI with additional text fields available in a third-party bug tracker. To do this, I want to send a javascript: command to the address bar using Ctrl+L and having AutoHotKey paste in the full call to the JS file.
A visualization of a possible environment:
The problem:
I need the user to be clicked INTO Flash in order to pull the data logs. However, I need the user to be clicked OUT of Flash for Ctrl+L to actually work - Flash appears to eat all keystrokes at the browser-level when one of its objects has focus.
A possible solution: The easiest way to go about this would be to simulate clicking on the stage, which borders my Flash object on every side. This should work, but I must assume the stupidest possible user. Such a user would somehow limit their current browser window to only be as big as the Flash object (if not smaller), click into it, and attempt to use the hotkey. In this case...I have no idea where I should click, because it could be outside the browser. Further, I don't believe I can assume that all browser address bars are similar amounts of pixels south from the top of the window.
Additional complicating factors:
I want this to work for the user's default browser. (IE, Chrome, Firefox, Safari are my big targets.)
AHK does not provide any native DOM or COM hooks to anything except IE.
Ctrl+Tab and Alt+Tab shenanigans do not appear to work. That can get me to other tabs/windows, but returning to the tab/window with the Flash object still causes Flash to 'eat' further keyboard input.
While I'd be open to using another scripting language than AHK if it could overcome this Flash focus hurdle, I do not know how to create a keylistener that sits in the users tray until activated by a hotkey.
I have no access to the Flash object's code, and it contains no logic to interpret a key combination as a way to break focus or launch a script.
Would it be possible to use WinMaximize to maximize the size of the window? If you do that it should be easier to set up the script to avoid clicking outside the browser.
Perhaps look at ControlFocus and/or ControlSend (using the "edit1" control in IE and FF -- unfortunately, Chrome doesn't expose the "address bar" as a "control" this way but if you test for Chrome first, you can implement your "click outside the Flash box" method for that case).

Javascript disable switches current tab functionality in browser

Is there a way to accomplished this on browser?
Disable opening another web page
or disable switch current tab functionality in browser
when certain page (in this case my page) is still open?
I want to make a quiz in web, but i want to eliminated the posibility for user search on internet for the answer, but have no idea how to accomplished that.
plis give me a solution..
regards..
No, this isn't possible, for (what I hope are) obvious reasons.
This not possible.
Even if it was possible in theory, how would you stop the user opening another browser (different brand to the current one)?
How would you stop the user from using their mobile phone to search the web?
If this quiz is being run in a controlled environment (like a classroom) you could run the web browser in some sort of kiosk mode with strict policy setup against opening other tabs etc. But if it is being run in a classroom, then you already have someone supervising anyway. Why bother then

javascript for new tab (CTRL+T), new window (CTRL+N)?

When flash has keyboard focus, CTRL+T (new tab) and CTRL+N (new window) are intercepted by flash.
Is there a way to pass these events through to the browser so that they work (opening new tab, opening new browser) OR is there a javascript command for these actions?
This is a long standing issue with Flash and browsers. (And I mean long - check out this eight-year-old bug on Mozilla browsers.) The problem is that Flash intercepts all input events, rather than the browser. It's sandboxed in its own environment, and doesn't pass events back to the browser.
Conceptually, this isn't necessarily a bad thing. What happens when Flash wants to listen to a ctrl + n event? Should the browser take focus away from Flash because it uses that hotkey already? It'd be a real pain for Flash developers, that is for sure.
There have been proposals on how to fix this issue that I've seen for particular browsers, but there's no catch-all solution. For example, this solution is referenced in the bug, but it obviously won't work the way you want (since the user will have to jump through quite a few hoops to get it working).
So... no, for now. Would be really neat if this problem could be fixed.
Closest you could get is to have ActionScript trigger Javascript to open a blank window to a blank URL
// We abstract it in a function here in case we want to
// change it later
function openBlankWindow()
{
window.open( '' );
}
For most people, this will launch a new window or a new tab (depending on their browser preferences) but since it is being initiated by the web page, may be subject to pop-up blockers.
There is no way to actually ask the browser to specifically do one of the two tasks you are asking about. I would be a security/annoyance nightmare if web pages had the permissions/privileges to do that.

Is there anyway to trap the closing of a web browser?

Two years ago I had a need to trap the closing of a web browser as a javascript event for a web app. At the time I found there was no way doing this that worked for all browsers. IE had an event that I could used, but it was IE specific. I looked into other work arounds, like a heart beat sort of ping to the server, but I didn't like any of them at the time.
Is there anyway currently to trap the closing of a web browser now? Thanks!
You can use the
window.onbeforeunload
javascript event to do this, though this will trap more than just closing the browser. This event will also get fired each time someone tries to navigate to another page, refresh the current page, etc. It's handy if you're trying to do something like warn people of unsaved changes before they leave the current page.
onunload works in IE and Firefox.

Categories

Resources