admin管理员组文章数量:1435859
Is there any way to programmatically dismiss navigator.notification.alert()? I alert when there's a location services error, but if it clears, I'd prefer to dismiss it rather than require the user to do it manually.
Any ideas or solutions?
Thanks!
Is there any way to programmatically dismiss navigator.notification.alert()? I alert when there's a location services error, but if it clears, I'd prefer to dismiss it rather than require the user to do it manually.
Any ideas or solutions?
Thanks!
Share Improve this question asked Aug 31, 2011 at 0:27 InatorInator 1,0242 gold badges16 silver badges34 bronze badges3 Answers
Reset to default 2Hey i have got a change in java file for this. src/android/Notification.java
Added a reference to dlg.create()
First Declare this..
private AlertDialog alertbox;
Then add a case where you send "dismiss" from javascript
else if (action.equals("dismiss")) {
this.dismissAll();
}
Method to be added :
public void dismissAll(){
alertbox.dismiss();
}
Do remember to add the same in notification.js in www folder of notification plugin
dismiss: function(message, pleteCallback, title, buttonLabel) {
var _title = (title || "Alert");//Doesnt Matter!
var _buttonLabel = (buttonLabel || "OK");//Doesnt Matter!
exec(pleteCallback, null, "Notification", "dismiss", [message, _title, _buttonLabel]);
},
Now add
alertbox = dlg.create();
alertbox.show();
instead of
dlg.create();
dlg.show();
at all the places.
And you are good to go by calling
navigator.notification.dismiss("",null,"");
This will dismiss all the alerts / confirm / prompt opened.
You can't programmatically dismiss an alert()
dialog, no.
What you could do, however, is instead of using alert()
implement your own custom overlay that looks/acts similarly to an alert, and then you can easily dismiss that whenever you want. Some additional discussion is here:
Javascript close alert box
Edit
I did a bit more investigation into this and I no longer believe that the Phonegap alert()
dialog is actually the same as the native JavaScript dialog. They are using some clever tricks to call back into native code (on both Android and iOS) to show the alert.
As such, it may be possible to dismiss the dialog programmatically, but almost certainly not from directly within your JavaScript code. You would need to use some similar trickery to call back from your JavaScript into native code, and then locate and dismiss the Phonegap alert view. The first part may be fairly difficult. The second part is trivial:
Hide UIAlertView programmatically?
Perhaps create a dialog out of a div or some other element and display that to the user so you can dismiss it easily.
JavaScript
function geo_error() {
//only append error message if none exists
if ($('#page_container').find('.geo_error').length == 0) {
$('#page_container').append('<div class="geo_error">A Geolocation Error Has Occured</div>');
}
}
function get_success(position) {
//hide the error message on success
$('#page_container').find('.geo_error').hide();
}
CSS
.geo_error {
position: absolute;
top: 10px;
bottom: 10px;
left: 20px;
right: 20px;
z-index: 1000;
}
本文标签: javascriptHow to dismiss a phonegap notification programmaticallyStack Overflow
版权声明:本文标题:javascript - How to dismiss a phonegap notification programmatically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745675893a2669848.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论