使用 PhoneGap HTML 在 iOS 中自定义 JavaScript 警报
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9432615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom JavaScript alerts in iOS using PhoneGap HTML
提问by Blynn
My app has a couple of JS alerts and it seems to always display the page name like.
我的应用程序有几个 JS 警报,它似乎总是显示页面名称。
index.html
索引.html
Is there a way to change the index.html to my App's name or custom text.
有没有办法将 index.html 更改为我的应用程序名称或自定义文本。
Example:
例子:
My App // Which replaces .index.html
alert("I am an alert box!");
回答by Zorayr
To be able to test on both a desktop browser and PhoneGap application, I suggest to use a dynamic approach as such:
为了能够在桌面浏览器和 PhoneGap 应用程序上进行测试,我建议使用动态方法:
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();
}
}
回答by Drew Dahlman
Like Simon said check out the notifications it's part of the phonegap API.
就像西蒙说的,查看通知,它是 phonegap API 的一部分。
You call it like this -
你这样称呼它——
Notification with options:
带有选项的通知:
navigator.notification.confirm(
"This is my Alert text!",
callBackFunction, // Specify a function to be called
'Alert Title',
["Ok", "Awesome"]
);
function callBackFunction(b){
if(b == 1){
console.log("user said ok");
}
else {
console.log("user said Awesome");
}
}
A simple notification -
一个简单的通知——
navigator.notification.alert(
"This is my Alert text!",
callBackFunctionB, // Specify a function to be called
'Alert Title',
"OK"
);
function callBackFunctionB(){
console.log('ok');
}
Hope that helps!
希望有帮助!
回答by Simon MacDonald
Use navigator.notfication.alertas you can provide your own title.
使用navigator.notfication.alert,因为您可以提供自己的标题。