Detect Idle Silverlight Application - javascript

What's the simplest way in Silverlight to detect the user is not active?
i.e. no mouse input and keyboard input for a period of time.
I tried monitoring the mouse events, keyboard events and the focus events of the root visual but it doesn't seem enough.
For example, a popup window may be open and these events won't reach the root visual.
Maybe javascript solution?
And then comes the other problem. When the application is idle I would like it to appear gray (just like ChildWindow behavior). And I would like it to appear like this even if there is an open ChildWindow or a simple Popup at the moment.

Are you sure the child window doesn't bubble? It is a routed event ... didn't realize that.
If not, just create a contract like:
ILastActivity : INotifyPropertyChanged
void Touch();
DateTime LastActivity { get; private set; }
Then you could create an attached behavior, a base class, or use any other mechanism to simply register the key events on your views. They all would call "Touch" when fired, and your timer would inspect LastActivity to determine it. Might be something you can do with automation peers as well, worth looking into.

Related

How to popup a virtual keyboard to enable user to fill out fields of an external page running in iframe on Chrome

I have a web app running on Chrome on Ubuntu. My screen is a touch screen, and there is no keyboard available for the user.
I'm using my own JavaScript keyboard on each screen that needs input.
Now, I need to embed an external form in my app inside an iFrame. I have no control over this page's content.
My question is how can I provide a keyboard for my users to fill these iFrame fields?
I explored 2 options:
Trigger keyboard events - failed, since were deprecated mostly due to a security problem
Show chrome's virtual keyboard - couldn't find a way to control when it pops up, since I don't want it on my own pages.
For anybody finding this years later like me:
There's actually no complete answer to this because there's a couple of problems.
You could actually add event listeners for both focus/focusin and blur/focusout to the document of said iFrame.
It works, but there's loads of pages with nested iFrames for login etc.
If you now try to add listeners to their documents too, CORS will block it.
That's actually a good thing because we could listen to keypress events as well and get passwords etc.
Now even if you deactivate CORS (which you of course should not), you would still need a MutationObserver as well, because many pages mutate the DOM to show inputs and whatever.
The Nodes would have to be 'scanned' for inputs and iFrames too, and the documents of the iFrames too.
So you see it'll be a huge recursive mess, that's probably pretty bad for performance as well. Not to forget the vulnerability that comes with it.
That's why most Virtual Keyboard extensions, for example for Chrome, just don't work for said iFrames.
If you want to do it like them, you basically just have to define a whitelist for keyboard dependent input types, select the iFrame and do:
iFrame.contentWindow.addEventListener('focus', (e) => {
if ((e.target instanceof HTMLInputElement &&
WHITE_LIST.includes(e.target.type))
|| e.target instanceof HTMLTextAreaElement)) {
//summon keyboard
}
}, true);
For 'blur' (keyboard closing) you don't even need the conditional.

Watch website and wait for events

I want to analyze a website that is not mine.
So, I want to use Javascript to do it at my end in the browser.
After I click a button on the website I want to trigger a timer and as soon as a notification from the website comes back, the timer should stop and save the notification that came back.
How can I do this the easiest way?
I cannot give you the link to the website, because it's hosted in a private network.
My first question would be, how I can log all events that are triggered on a website to the console, so I know the name of the button I want to wait for.
Thanks!
dave
All events on a specific DOM node:
To see all the events for a specific DOMnode, or window (only works on chrome i believe, didnt test it elsewhere):
getEventListeners(window)
this will give you an object with all the events, then you can intercept them with
window.addEventListener(eventName, fn, true);
The whole application:
this way your event will be called whenever an event on that node is triggered (window in this case)
if you want absolutely all events on the whole app, you can achieve it with using something like firebug
Specific event on a specific element:
if you want a button click only, you can do the following:
var specificButton = document.querySelector('#specific-button')
specificButton.addEventListener('click', function() {});
Implementation:
if you do not own the sourcecode, you can use something like greasemonkey or tampermonkey to inject your javascript into the page.
if you are using it on a server, you can use cheerio to parse the returned html from the get request, and apply queries on it, but you will lose the ability for listening to live events from io devices.
If I understand you, the easiest option I see is to open your browser developer tools and using the console get the button (document.getElementById, i.e.) and change its onclick callback, including a call to the old callback in your new callback, and trigger your timer.
To intercept the response to this button (I assume that it triggers a network request), you'll have to analyze a bit the code of the web to see how you can detect it.
You could also edit the website javascript throught "Sources" tab of your browser's dev tools.
It's an idea. I have never done something like that. I have to admit that it sounds a little weird to me.

parent.opener doesn't work in webview Android

I have a problem. I need to return to parent Url from Frame opened in a Android Webview.
The sequence is: Open inside Webview new frame. Select in frame options and paramters. Call in frame javascript function like _"javascript:parent.opener.jsfunction"_. Parent Web doesn't open...
I don't have access to Web. I work only in Android side.
I test Web in a firefox for Android and it works.
Need help.
By default, WebView doesn't support multiple windows. If you check, I believe the parent field actually isn't set and doesn't point to the parent window (or anything at all). The same applies to other similar fields like opener and top.
You might be able to work through this by enabling support for multiple windows and then implementing onCreateWindow in your WebChromeClient. I think there's some more you have to do, but it's been a while and I don't recall the details.
One way I've hacked around this in the past is to use setJavascriptInterface and just set the name to parent or whichever field you want. Implement the appropriate methods as necessary on your Java object. This can get a bit messy, but it works.

titanium javascript events

I have been using Titanium for an Android application that does some microblogging through restful web services. Everything works fine, but I am using tabhost to store five windows at the same time and some of these windows use same event handlers to get same kind of data. So when you get some kind of data from server, events from multiple windows may start to work. And these events may fire other events and things got all messed up.
Is there a way to suppress other objects and just enable the object in focus? How can I prevent this situation?
One way that I managed things like that is to hook my actions to the focus event of the window the user is actually opens. Then use whatever I need to render that window. It might be that you're trying to update all windows before the user is actually opens them. That's not really necessary. Wait until they open the window and then update it. As long as you have the data set up, rendering the window is quick and you can do it realtime and without too much delay.
On a mobile, you really have to try to do things as late as possible.

Prevent a webpage from being closed or navigated away from

No, I'm not trying to make an annoying popup. I have a simple webpage that is a web-based control for a SOA tool that will allow our clients mobile access to systems we put in their locations. If the user closes the webpage without using a "Disconnect" button that closes the communication tunnel on the service side before closing the window itself, the system remains active until the service times out. That may not sound terrible, but the same communication tunnel is used by in-house staff in high-priority situations, and if they cannot access it because the customer's web service is tying it up, that is a Very Bad Thing.
So, I want to prevent the user navigating away from the page or closing the tab or browser instance by any other means than clicking "Disconnect". I'm sure it's possible, I just need a nudge in the right direction. The solution must be as browser-agnostic as possible, especially concerning mobile browsers.
You can try using the onbeforeunload handler. but it is not always thrown.
See fiddle using jQuery: http://jsfiddle.net/maniator/qpK7Y/
See fiddle with pure javascript: http://jsfiddle.net/maniator/qpK7Y/10/
You can't stop the using from closing the window via the close button at the top right. You can force a child window to retain focus like this though:
Declare a global variable:
var childWindow;
Assign the variable to a window object
childWindow = window.open("...", "...");
if (childWindow){
childWindow.focus();
}
To force focus on the child window, use the onfocus event on the parent:
focusChildWindow = function(){
if (childWindow != null){
childWindow.focus();
}
}
<body onfocus="focusChildWindow();" ...>

Categories

Resources