How do I put a warning/message on a specific number of a counter?












-2















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?










share|improve this question

























  • 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


















-2















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?










share|improve this question

























  • 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
















-2












-2








-2








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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





















  • 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














1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









1














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.






share|improve this answer
























  • 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
















1














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.






share|improve this answer
























  • 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














1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values