Simulating pop ups in windows javascript app - javascript

I'm porting my webpage chat to windows 8 javascript app. I need to simulate pop-ups like alert, prompt, confirm,... Creating the box isn't problem, but the main part is that I need to pause script execution somehow until user clicks the button.
Is there any way to do it (I know that in pure javascript, it is hard, but I think that there may be some kind of windows native function to pause execution (or there may be some way to implement alert,... directly))?

epascarello-- why do you say that its not makeable, if you dont know it.
use Method showModalDialog , search for it,

Related

Writing A Program that clicks a Chrome alert box

I have an alert that comes up in chrome, it slides into the browser on the top right hand side of the window. Every time this specific alert comes up I have to move my mouse over and click the alert box which will then open up a link in a new window. I have to do this multiple times a day. I'd be great if I could write a Javascript or Python program that will automatically "click" the box every time it comes up in the browser. Is there a way to do this? I have a little over a year of programming experience but I don't expect a step by step answer, just set me off in the right direction. I've looked up browser events hoping I could just write an event listener function but I couldn't find one specifically for browser alerts.
If it is the native modal of the browser, then the short answer is no.
You can't do it with javascript as the confirm (alert) pop up is a blocking modal.
No javascript code can run while the confirm modal is open.
If this is a custom modal that built and controlled by javascript then there is a good chance of doing just about anything you want with it.

How to get text input from user in Chrome Extension [duplicate]

I'm currently developing a Chrome Web App using the Chrome Platform APIs and Javascript and I simply can't find a way to display a prompt() dialog to ask the user for a value, in a way that prevents him from clicking anywhere else until he enters a value and accepts or cancels (meaning, EXACTLY how it works with Javascript).
My problem is, I just can't find a way to do this with the Chrome Platform APIs (note that prompt(), alert() and confirm() can't be used in packaged apps). I already checked questions similar to mine and they all point to the Google App Script documentation, which doesn't work for Chrome Apps.
The only "solution" that I've really found is making a new window, enabling singleton so that it can only be an instance of it and displaying a form there, getting the value when the user accepts(I haven't really finished that last part, I need a way to check when the window is being closed by a button). Still, this is kind of a lot for a simple dialog.
Is there a simple way to do this that I'm missing or is the "intended" way to do this to use multiple windows?
window.prompt has two features:
It requests input from the user.
It does this in a synchronous way, i.e. execution of JavaScript in your page is suspended until prompt() returns.
The first feature can be emulated, but the second feature cannot. So, you will be able to get user input, but only in an asynchronous way. There are two ways to prompt the user for input:
In a popup.
In a lightbox.
A lightbox is similar to a popup, except that it's embedded in the page itself. All implementations of a lightbox involve at least two containers:
A div that covers the whole page, so that the user cannot click on anything else. (CSS: position:fixed;top:0;left:0;width:100%;height:100%;z-index:1000;)
Other HTML elements that together resemble a dialog (input fields, buttons).
There are plenty of existing UI libraries to show an inline dialog, e.g. jQuery UI.

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).

Prevent Phonegap notification.navigator popups from closing from touch outside of dialog

I am using Phonegap to build an Android application and am running into problems using functionality that is not well documented for Phonegap.
navigator.notification.activityStart('title', 'message');
The above works fine, and using it with activityStop() opens and closes the loading dialog when I need it to. The problem is that if the user touches the screen or hits the back button the loading dialog closes. I want it to remain open until I am done loading a document from a server in the background.
I am running into the same problem with navigator.notification.alert and the other functions of the navigator.notification.
Also, I would prefer to not modify any native code. I know that I could probably edit the Phonegap plugin native code to achieve this, but this application will eventually be cross-platform so I would prefer to not do any native code if possible.
I found a solution which I integrated in my application and it worked.
In java file of notification alert do the following change :
=> go to alert ()
=> dlg.setCancelable(false);
Good luck

Emulate Javascript 'alert' blocking nature

Is it possible to create a custom modal message which 'blocks' the execution of the script until a user input?
For example, how can you achieve this without using the native window alert / prompt functions?
setInterval(function(){
alert('Click OK to Continue'); // timing stops until user hits ok
},4000);
I know you could have your custom dialog invoke a callback function on user input, but I'm interested in being able to force this blocking behaviour
Is it possible to create a custom modal message which 'blocks' the execution of the script until a user input?
No. There is no way to block either execution or user interaction as effectively as a native popup (since with custom popups the user is always technically capable of using developer tools to get out of it).
However, as pst says in the comments on the question, asynchronous lightboxes are not onerous, and are almost as effective at blocking user interaction as popups, so I recommend finding a library that provides lightboxes you like and running with that.
For example, how can you achieve this without using the native window alert / prompt functions?
You can't use that code to do what you say it will even with native window alert / prompt functions (see this fiddle - wait 4 seconds before closing popup). You'd need the following:
function timeoutFunction() {
alert('Click OK to Continue'); // timing ACTUALLY stops until user hits ok
setTimeout(timeoutFunction, 4000);
}
setTimeout(timeoutFunction,4000);
Which is something that you can't implement (precisely - see above on lightboxes) without native popups.
Even while(true) loops won't generally block as well as a popup - firefox at least has a "stop script" message that pops up after it's been going too long, and I'm fairly sure other major browsers do too.
No, you can't (at least not in a browser). Javascript APIs are mostly async. alert/prompt are exceptions. However, it's not very hard to work with async prompts and callbacks.
A bit old, but in case it helps, I've found my solution with this:
var answer = confirm("are you sure?");
if(!answer)return;

Categories

Resources