How do I put a warning/message on a specific number of a counter?
I am using a system in my website that identify the amount of battery the user have in his phone, the system is "battery-api".
I would like to insert a warning when the battery is over 10% (for example) like, "Hey, you need to charge your phone, you can always use our products..."
it's possible?
javascript jquery battery batterylevel batterymanager
add a comment |
I am using a system in my website that identify the amount of battery the user have in his phone, the system is "battery-api".
I would like to insert a warning when the battery is over 10% (for example) like, "Hey, you need to charge your phone, you can always use our products..."
it's possible?
javascript jquery battery batterylevel batterymanager
Yes, It is possible if user is using latest chrome browser. More caniuse.com/#feat=battery-status
– Niraj Kaushal
Nov 15 '18 at 17:37
developer.mozilla.org/en-US/docs/Web/API/…
– Mosh Feu
Nov 15 '18 at 17:40
What did you try? What problems were encountered? That API has limited browser support
– charlietfl
Nov 15 '18 at 17:42
add a comment |
I am using a system in my website that identify the amount of battery the user have in his phone, the system is "battery-api".
I would like to insert a warning when the battery is over 10% (for example) like, "Hey, you need to charge your phone, you can always use our products..."
it's possible?
javascript jquery battery batterylevel batterymanager
I am using a system in my website that identify the amount of battery the user have in his phone, the system is "battery-api".
I would like to insert a warning when the battery is over 10% (for example) like, "Hey, you need to charge your phone, you can always use our products..."
it's possible?
javascript jquery battery batterylevel batterymanager
javascript jquery battery batterylevel batterymanager
edited Nov 15 '18 at 18:27
Aravind Bhat K
2991215
2991215
asked Nov 15 '18 at 17:33
Paulo LimaPaulo Lima
1
1
Yes, It is possible if user is using latest chrome browser. More caniuse.com/#feat=battery-status
– Niraj Kaushal
Nov 15 '18 at 17:37
developer.mozilla.org/en-US/docs/Web/API/…
– Mosh Feu
Nov 15 '18 at 17:40
What did you try? What problems were encountered? That API has limited browser support
– charlietfl
Nov 15 '18 at 17:42
add a comment |
Yes, It is possible if user is using latest chrome browser. More caniuse.com/#feat=battery-status
– Niraj Kaushal
Nov 15 '18 at 17:37
developer.mozilla.org/en-US/docs/Web/API/…
– Mosh Feu
Nov 15 '18 at 17:40
What did you try? What problems were encountered? That API has limited browser support
– charlietfl
Nov 15 '18 at 17:42
Yes, It is possible if user is using latest chrome browser. More caniuse.com/#feat=battery-status
– Niraj Kaushal
Nov 15 '18 at 17:37
Yes, It is possible if user is using latest chrome browser. More caniuse.com/#feat=battery-status
– Niraj Kaushal
Nov 15 '18 at 17:37
developer.mozilla.org/en-US/docs/Web/API/…
– Mosh Feu
Nov 15 '18 at 17:40
developer.mozilla.org/en-US/docs/Web/API/…
– Mosh Feu
Nov 15 '18 at 17:40
What did you try? What problems were encountered? That API has limited browser support
– charlietfl
Nov 15 '18 at 17:42
What did you try? What problems were encountered? That API has limited browser support
– charlietfl
Nov 15 '18 at 17:42
add a comment |
1 Answer
1
active
oldest
votes
You can achieve the functionality using the Battery Status API. The below code is a slightly modified version of the Example on this page.
navigator.getBattery().then(function(battery) {
battery.addEventListener('levelchange', function(){
updateLevelInfo();
});
function updateLevelInfo(){
var percentage = battery.level * 100;
if(percentage < 10){ // Show message };
}
});
I recommend checking the browser compatibility however if it's satisfactory.
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
1
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325009%2fhow-do-i-put-a-warning-message-on-a-specific-number-of-a-counter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can achieve the functionality using the Battery Status API. The below code is a slightly modified version of the Example on this page.
navigator.getBattery().then(function(battery) {
battery.addEventListener('levelchange', function(){
updateLevelInfo();
});
function updateLevelInfo(){
var percentage = battery.level * 100;
if(percentage < 10){ // Show message };
}
});
I recommend checking the browser compatibility however if it's satisfactory.
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
1
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
add a comment |
You can achieve the functionality using the Battery Status API. The below code is a slightly modified version of the Example on this page.
navigator.getBattery().then(function(battery) {
battery.addEventListener('levelchange', function(){
updateLevelInfo();
});
function updateLevelInfo(){
var percentage = battery.level * 100;
if(percentage < 10){ // Show message };
}
});
I recommend checking the browser compatibility however if it's satisfactory.
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
1
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
add a comment |
You can achieve the functionality using the Battery Status API. The below code is a slightly modified version of the Example on this page.
navigator.getBattery().then(function(battery) {
battery.addEventListener('levelchange', function(){
updateLevelInfo();
});
function updateLevelInfo(){
var percentage = battery.level * 100;
if(percentage < 10){ // Show message };
}
});
I recommend checking the browser compatibility however if it's satisfactory.
You can achieve the functionality using the Battery Status API. The below code is a slightly modified version of the Example on this page.
navigator.getBattery().then(function(battery) {
battery.addEventListener('levelchange', function(){
updateLevelInfo();
});
function updateLevelInfo(){
var percentage = battery.level * 100;
if(percentage < 10){ // Show message };
}
});
I recommend checking the browser compatibility however if it's satisfactory.
answered Nov 15 '18 at 17:41
Adriani6Adriani6
4,95721528
4,95721528
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
1
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
add a comment |
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
1
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
I feel dirty knowing that this solution, while valuable information, is going to lead to ads for phone chargers based on battery state given the question.
– gelliott181
Nov 15 '18 at 17:46
1
1
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
Firefox removed support for the API in Firefox 52 due to privacy concerns. groups.google.com/d/msg/mozilla.dev.platform/5U8NHoUY-1k/…
– Niraj Kaushal
Nov 15 '18 at 17:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325009%2fhow-do-i-put-a-warning-message-on-a-specific-number-of-a-counter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes, It is possible if user is using latest chrome browser. More caniuse.com/#feat=battery-status
– Niraj Kaushal
Nov 15 '18 at 17:37
developer.mozilla.org/en-US/docs/Web/API/…
– Mosh Feu
Nov 15 '18 at 17:40
What did you try? What problems were encountered? That API has limited browser support
– charlietfl
Nov 15 '18 at 17:42