How to press a button with java-script event inside a web-page by code for iOS (iPhone)? - iphone

I am writing an application for iOS (iPhone).
How to press a button with java-script event inside a web-page? I need to write a code to press this button. Then the event will be executed. And I'll take result of it's work.
Thanks a lot for help!

You can use:
document.getElementById('id-of-button').click();
This will perform a click event on the button.
EDIT: to run JavaScript in a UIWebView use the stringByEvaluatingJavaScript: method. Eg:
[webView stringByEvaluatingJavaScript:#"document.getElementById('id-of-button').click();"];

Related

Programmatically dismiss modal dialog in MacOS

I have a warning dialog from a MacOS application's AppDelegate that needs to be updated with new information. When the new information is available, I want to programmatically dismiss the old dialog and present the new one. I have tried this two ways, both with problems:
Using alert.runModal()
If I use the above, a modal is presented as desired. I can then dismiss the dialog later with lockWarningModal.window.close(), it works to make the old dialog disappear, but it freezes the UI, so I can no longer interact with it. I am guessing this is because alert.runModal() is synchronous, and the main thread is still blocked. However, I don't know how to release this.
Using alert.beginSheetModal(for: NSApplication.shared.windows.last!) { (response) in }
If I use the above and dismiss the dialog with NSApplication.shared.windows.last!.endSheet(alert.window), then this solves the UI freeze problem. However, the dialog is attached to the main application window and is not brought to the front as a modal.
How can I achieve a modal dialog that is programmatically dismissible?
You can't stop a model event loop (or alert sheet) by simply closing its window. In fact, using the modern NSAlert API, you should never have to close or order out the window—the framework handles this for you.
For an alert started with runModal() use NSApplication's abortModal(), stopModal(), or stopModal(withCode:). After runModal() returns, send the alert window an orderOut(nil) to remove it.
For an alert sheet that executes a completion block afterwards, use NSWindow's endSheet(_) or endSheet(_:returnCode:). The alert will be automatically removed after your completion block executes.

Vaadin (7.0.5) Window not opening until end of calling procedure

I am trying to open a modal window during a click handler to verify the user action but the window doesn't appear until the handler completes. The window code can be as simple as the following and it still will not display so it isn't something to do with my abstract class.
Window w = new Window();
w.setModal(true);
w.setImmediate(true);
// Add components etc etc
UI.getCurrent().addWindow(w);
I could add the action code to the windows OK/Yes handler but that would stop me creating a generic Message class to simplify/stop code duplication.
I am guessing there is something I dont understand about how Vaadin/GWT works (still a newbie!), could someone point me in the right direction?
Cheers
For UI stuff, you have to stop thinking of sequencial programming,
better to think about event-driven concepts.
For Vaadin you could create a Dialog Window which asks the yes/no question.
In you app you create this dialog and display it.
And you attach a event-handler which is fired when the user clicks yes/no,
and inside this handler you then do the required actions in your code.
You can also look at this add-on
https://vaadin.com/de/directory#addon/confirmdialog
The right direction is architecture overview https://vaadin.com/book/vaadin7/-/page/architecture.html#architecture.overview
In other words your code makes only response from server side, but only client side can show "modal" window.
In your case you have to create handler for ok button click event and wait for this event

Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

I have a hook on the beforeUnload event. If i try to click on a link, reload or close the tab or the navigator, the app ask for confirmation before leaving. That's the desired behavior.
But if click on the back button or the backspace outside an input, no confirmation.
At the beginning of the html :
window.onbeforeunload = function() {
if (confirmEnabled)
return "";
}
And i use the Gwt PlaceHistoryMapper.
What did i miss ? Where did i forgot to look ?
Thanks !
As long as you stay within your app, because it's a single-page app, it doesn't by definition unload, so there's no beforeunload event.
When using Places, the equivalent is the PlaceChangeRequestEvent dispatched by the PlaceController on the EventBus. This event is also dispatched in beforeunload BTW, and is the basis for the mayStop() handling in Activities.
Outside GWT, in the JS world, an equivalent would be hashchange and/or popstate, depending on your PlaceHistoryHandler.Historian implementation (the default one uses History.newItem(), so that would be hashchange).

mimic pressing a button on a webpage in the backgroud, for triggering an action

Pretend you have a button on an iOS GUI. Pressing this button should now trigger a button on a webpage (which triggers an action). While doing this, the webpage should not be visible. How can I do that?
My guess is, that I read and parse the webpage, and if I've found the button action, I would trigger it somehow. Since I'm not a web programmer, I wonder how to proceed or read on for such a task.
I need this task, because there is no JSON or XML webservice on the page that would make life easier.
Many thanks for any input
Okay, let's say you've already loaded your webpage in an off-screen (or hidden) UIWebView, and the submit button on that webpage looked a bit like the following in code:
<form id="my_submit_button" etc... >
Just call the following:
NSString* javascript = #"document.forms['my_submit_button'].submit();";
[myUIWebView stringByEvaluatingJavaScriptFromString: javascript];
Hope this helps!

Assigning Back button event to form button in android

i have a form button in the form,which i need to perform basic action performed by the back button in the android emulator.
I know the key even is KeyEvent.KEYCODE_BACK
how to assign this to my button.
thanks in advance.
The question isn't totally clear, but you probably just want to call finish() when your Button is clicked.
I found the solution to it.
call the function moveTaskToBack(true);
to get back to previous task.