jQuery-使用navigator.notification.alert [英] JQuery - Using navigator.notification.alert
问题描述
我要求弹出窗口带有自定义标题(让它从应用程序中的index.html看起来很俗气).
I have a requirement for a popup to appear with a custom heading (having it appear from index.html on an app just looks tacky).
我尝试了以下链接末尾的建议:
I tried the suggestion at the end of the following link:
使用PhoneGap HTML在iOS中自定义JavaScript警报
因此,我在脚本部分的index.html中添加了以下代码:
So I added the code below to my index.html in the script section:
function showMessage(message, callback, title, buttonName){
title = title || "default title";
buttonName = buttonName || 'OK';
if(navigator.notification && navigator.notification.alert){
navigator.notification.alert(
message, // message
callback, // callback
title, // title
buttonName // buttonName
);
}else{
alert(message);
callback();
}
}
更新
我有以下警报代码;
if ((inputNumber>maxAllowed))
{
showMessage("The input is too high.",null,"Warning","Warning");
}
编译应用程序后,此方法不起作用.
After compiling the app, this is not working.
以下是在index.html中:
The following is in index.html:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the PhoneGap API
}
<function shown above is here>
有人知道为什么这仍然行不通吗?从index.html显示
Any idea why this is still not working? Showing from index.html
谢谢.
亲切的问候,
Gary Shergill
Gary Shergill
推荐答案
此错误告诉您 navigator.notification
函数不存在.
This error tells you that function navigator.notification
don't exist.
通常这是因为:
- Phonegap/Cordova未在HEAD内初始化
-
函数未在deviceready事件中初始化.基本上,在cordova.js完全初始化之前无法调用函数.
- Phonegap/Cordova is not initialized inside a HEAD
Function is not initialized inside a deviceready event. Basically function can't be called before cordova.js is fully initialized.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the PhoneGap API
}
这篇关于jQuery-使用navigator.notification.alert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!