I have a web page that I'm loading in Safari on iOS 13.4.1. The web page calls DeviceOrientationEvent.requestPermission() and in the .catch following the .then I'm seeing this error:
NotAllowedError: Requesting device orientation or motion access requires a user gesture to prompt
However there is no pop-up requesting permission.
Does anyone know what I'm missing?
Late reply, hoping it might be useful to others.
The call DeviceOrientationEvent.requestPermission() in your code must be performed as a reaction to some user gesture.
So e.g. you would show a dialog to user with a message and a button, explaining what's going to happen next. In button click handler, you hide the dialog and actually call that method.
An example of click handler is given here: https://dev.to/li/how-to-requestpermission-for-devicemotion-and-deviceorientation-events-in-ios-13-46g2 .
Related
I am working on wicket 6.0. I used an AjaxButton to save a form. When I press the button, nothing happens on User Interface. However I checked the log and the onError method was called. What does it mean? How to fix it?
Moreover I checked on FireBug to see Ajax events, I have no events when I press the button.
Thanks
AjaxButton is a form submitting component. If its #onError() is called that means some FormComponent in the submitted form didn't pass its validation/conversion.
If #onError() is called then there is an Ajax call for sure!
This is not a cross-site attack because it happens on the same website.
Before we render to the browser, we figure out in server-side whether to render a button or not based on whether the user has sufficient credit in their account (example case). So, if they have insufficient credit, the check out button doesn't even make it to the page on page load.
Here's what they did:
Go to a purchase product page when they have sufficient credit. The check out button shows.
They look at Inspector (FireFox) or any other in-browser developer tool and copy the html input element that submits the form.
They purchase as normal. Now, they have insufficient credit.
They go to another purchase product page, and of course, the check out button will no longer show (because it didn't even make it on page load in the first place).
They open up their in-browser developer tool and paste the input element copied from the other previous page when they had sufficient credit. The button shows up on the rendered page. They click it, then they proceed as if they had sufficient credit.
The problem is, the submit button's event handler in code behind is unaware of the existence or non-existence of that submit button, and will execute if called, and that we give it a hard-coded id.
The obvious solution would be to do a credit vs. price check [again] on the click event handler. From inside the event handler, is there a way to determine whether the control existed on page load? I figure that the sender parameter would not be null if they pasted a control in-browser, so there's not much help there.
Any solutions on this?
The only safe solution to this is to check if the user has sufficient credits ON THE SERVER after the postback occurs.
protected void OnSubmit(object sender, eventargs e)
{
if (product.Price > User.Credits) {
throw new Exception();
}
purchase();
}
If you use the check the button approach then they can still use the JavaScript console to call __doPostBack
Never rely on the client side for authorization
You could store in ViewState whether the button was rendered or not; this is encrypted and cannot be changed on the client. If you set it as ViewState["ButtonRendered"] = true;, then you can check this to see if it's true or false, and act accordingly.
Because of the nature of the user opening up multiple browsers, and other tricks, I would 100% recommend you do another database query to make sure they have sufficient credit, and if not, display an error to the user. That would be the absolute best way of handling it. What would keep them from opening up firefox and chrome, and trying to attempt to simultaneously purchase two different items?
Maybe this is a dummy question, This is the scene.
I've got a web system (ASP.NET MVC 2.0). When I press the "Save" button all the process it's call and begin the execution. What happen if I:
1) Press another link to change view
2) Press again the submit button
Both scenes whereas the process not finish yet.
Regards.
The first controller (that handles the button) probably got the action, and then another controller got an action (from the link, if it's to the same site), and then the first controller gets the button action again.
your browser aborts the calls, but they are run in the server.
eventually the browser shows you the last result from the call that was not aborted.
If you want to observe this behavior use a debugger - and see the actions called.. and firebug - to see the browser aborts...
Can I tell, using javascript, whether a user has clicked on the "X" icon on a browser dialog, or the "OK"/"Cancel" buttons? I have code I need to run when the window closes, but it will only run when OK or Cancel are clicked.
I currently capture the onunload event of the window. How can i accomplish this?
window.onunload = function() { alert("unloading"); }
Why do you want to do this? We can probably help you come up with a different design that doesn't require this if you tell us what you're trying to do.
However, to answer your question: it's not possible to catch that event in all cases. You cannot prevent the user from closing the browser or guarantee that your code will execute when they do. You can make it slightly annoying for them, but they can disable javascript, or kill the process, or reboot the computer. Using the unload function is the closest you can come to having some code that runs when the window closes (it will run in cases of normal shutdown or when the user navigates away).
If I understood correctly, your question is about a browser dialog, not the main browser window.
To answer your question, you probably cannot distinguish between the Cancel button and the X button of a browser dialog. They'll both end up just returning a false. If you need this level of control, you should consider writing your own simulated dialog (lightbox) instead of a real JavaScript dialog. Or perhaps look at existing frameworks/plugins with modal dialogs that give you the amount of control you need.
What about if he does ALT + F4?
To the best of my knowledge, you can't detect whether the user closed the dialog by clicking the Cancel button or the [x] button, since neither are exposed to you beyond returning the result of the action (e.g., confirm() as true/false).
You can hook into the document.onbeforeunload event to perform whatever cleanup action you require; I've done so myself by sending an asynchronous XMLHTTP request to the server to make sure the user's session gets cleaned up properly.
It is impossible to catch the closing of the browser and handle every other event that also causes a post back. You can try and many people have before you and failed.
Your best bet is to use onbeforeunload and learn how to deal with session timeouts on your serverside to clean up data.
I have an HTML wrapper that contains a Flex application, is there an Event that I can listen on, that is triggered when a user leaves the HTML wrapper either by navigation arrows or closing the browser?
Thanks.
You can also listen for Event.ACTIVATE and Event.DEACTIVATE in Flash. All EventDispatchers receive these events when Flash/AIR gains or loses focus from the OS.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/EventDispatcher.html#event:deactivate
This is very helpful for when you you provide a link that opens a new window and you want to reduce functionality and load (pause and mute a video for example) and then resume when the user comes back.
Edit: I realized this may not be what you're asking for exactly, but I'll leave it in in case it's helpful for anyone looking for it. Also note that you can perform other actions in the onbeforeunload event that will generally be reliably executed before the user accesses the confirmation dialog, unless your unload routine is overly complex (in which case you should consider altering your design anyway).
onbeforeunload lets you interrupt page unload:
window.onbeforeunload = function(e) {
// Browser will pop up a confirmation dialog, with some text before
// and after your return string; try it in different browsers to
// see how they behave.
return 'String to confirm';
}
There is Body.onUnload, but i'm not sure how reliable it actually is.
The closest thing I've found for this is the javascript window.onunload event. However, you can't really listen for this within the Flex app, as the app may not be running anymore by the time the unload method is called. We've used it to signal to other parts of the page via javascript that the app was unloaded though, so depending on what you need to do that might be enough.
The question is, what do you need to do when the user navigates away?
If you need to perform an action on your server, then the best way to handle this is to open a Socket() when your swf initializes, and then when the user navigates away, that socket will be terminated, and the server can detect that and perform additional logic.
If you need to perform a client side operation, like saving a SharedObject, then you can't rely on a "just one last thing" event to the plugin, since there are alot of avenues to closing out a plugin session. In that case, your best bet is to continually be saving SharedObjects every few seconds.