Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: JavaScript help...

10 Oct 2010   #1
Benjamin Hall

Windows 7 Ultimate x86
 
 
JavaScript help...

So I'm working on adding functions to my battery gadget, and one function I'm trying to add will bring the gadget to the front (make it appear above all other windows) once the battery gets down below 21% (I'll wind up adding a function too that will make it coincide with the user's setting for low battery level) and so I know the main functin will be.

if
(percent < 21)

and then the rest of the function

but I'm not sure what to use...
and code monkeys on here?

I'm not sure if I should use

onBlur='self.focus()'

or not...
My System SpecsSystem Spec
11 Oct 2010   #2
Everlong

 

self.focus() should be fine to use for what you want.
My System SpecsSystem Spec
11 Oct 2010   #3
Benjamin Hall

Windows 7 Ultimate x86
 
 

Okay, cool. I figured it would be, but wanted to be sure.

So, I tried simply adding it to the "update" function area of my code (the area where it updates the icons based on battery percentage) and it didn't work...

Here is what I tried (I'll just post the entire "update" function so you can see it in context)

Code:
function Update()
{
  //delcare variables for displaying battery icons.
  var percent = FixedPercent(System.Machine.PowerStatus.batteryPercentRemaining);
  var percentString;
  var timeString;
  var battIcon;
  var onPower = false;
  var charging = false;
  //declare percentage zones for displaying battery icons. 
  //This can be easily edited to fit a new icon set if the set contains more or less icons than what is already here.
  //Simply take 100 and divide it by the total number of battery icons you want to use, then edit the percentages accordingly.
  if (percent > 95)
  {
    battIcon = 17;
  }	
  else if (percent > 89)
  {
    battIcon = 16;
  }
  else if (percent > 83)
  {
    battIcon = 15;
  }
  else if (percent > 77)
  {
    battIcon = 14;
  }
  else if (percent > 71)
  {
    battIcon = 13;
  }
  else if (percent > 65)
  {
    battIcon = 12;
  }
  else if (percent > 59)
  {
    battIcon = 11;
  }
  else if (percent > 53)
  {
    battIcon = 10;
  }
  else if (percent > 47)
  {
    battIcon = 9;
  }
  else if (percent > 41)
  {
    battIcon = 8;
  }
  else if (percent > 35)
  {
    battIcon = 7;
  }
  else if (percent > 29)
  {
    battIcon = 6;
  }
  else if (percent > 23)
  {
    battIcon = 5;
  }
  else if (percent > 17)
  {
    battIcon = 4;
  }
  else if (percent > 11)
  {
    battIcon = 3;
  }
  else if (percent > 5)
  {
    battIcon = 2;
  }
  else
  {
    battIcon = 1;
  }

if (percent < 20)
{
  self.focus();
}
  
  percentString = percent + "%";
  if (System.Machine.PowerStatus.isBatteryCharging)
  {
    timeString = " ";
    charging = true;
  }
  else if (System.Machine.PowerStatus.isPowerLineConnected)
  {
    timeString = " ";
    onPower = true;
  }
  else
  {
    timeString = _timeRemaining.TimeRemainingString;
    if (timeString == "")
    {
      timeString = " ";
    }
  }
  if (_currentBattIcon !=  battIcon)
  {
    _imgBatt.src = "icons/battery_" + battIcon + ".png";
    _currentBattIcon = battIcon;
  }
  if (_currentTimeString != timeString)
  {
    if (_currentTimeString == " ")
    {
      //If transitioning to having a time string present, clear the large percent text and force the percent text to update below.
      _txtPercentageLarge.value = " ";
      _currentPercentString = " ";
    }
    if (timeString == " ")
    {
      //If transitioning from having a time string present, clear the small percent text and force the percent text to update below.
      _txtPercentage.value = " ";
      _currentPercentString = " ";
    }
    _txtTime.value = timeString;
    _currentTimeString = timeString;
  }
  if (_currentPercentString != percentString)
  {
    if (_currentTimeString == " ")
    {
      _txtPercentageLarge.value = percentString;
    }
    else
    {
      _txtPercentage.value = percentString;
    }
    _currentPercentString = percentString;
  }
  if ((_currentOnPower != onPower) || (_currentCharging != charging))
  {
    _currentOnPower = onPower;
    _currentCharging = charging;
    if (charging)
    {
      _imgPower.src = "icons/power_red.png";
    }
    else if (onPower)
    {
      _imgPower.src = "icons/power_black.png";
    }
    else
    {
      _imgPower.src = "icons/power_blank.png";
    }
  }
  setTimeout(Update, 2000);
}
But it didn't work. :/ I must be missing something lol.. .maybe I need to declare an entirely new function?
My System SpecsSystem Spec
.


11 Oct 2010   #4
Everlong

 

What exactly didn't work?
My System SpecsSystem Spec
11 Oct 2010   #5
Benjamin Hall

Windows 7 Ultimate x86
 
 

Well, I tested it out,

Code:
if (percent < 20)
{
  self.focus();
}
by letting my battery drain down below 20 percent, but it didn't bring the app to the front of all my other open widnows :/
My System SpecsSystem Spec
Reply

Thread Tools



Similar help and support threads
Thread Forum
IE9 - Problem with javascript
Hello, I have IE9 on Win7 x64 PRO SP1. I have a problem with javascript on a lot of websites - it doesn't work on normal browse, but when I refresh page (CTRL+F5) everything is ok. I checked this in developter tools, and there are many communicates like this one: SCRIPT: Permission...
Browsers & Mail
Help with Javascript?
Hi guys, I'm working on a site for a school project, and I got a scrolling sidebar using some Javascript I borrowed from somewhere. The thing is, it scrolls horizontally as well as vertically. I have no idea how to code Javascript and was wondering if any of the whizzes on here could help? ...
Chillout Room
Javascript error
This may not be the right place to ask this question. But I just want some info on this javascript error log. I get this error when I try to browse this website from Nokia N97 mini handset. The reply box is grayed out and I cant type in the box. I just want to know if there is any info in this...
Browsers & Mail
javascript
somebody can help me to find out good web for javascript tutorial or some reference on it.?? i'm tried to find out but didn't got a good one. your attention be my pleasure. thanks.
Chillout Room
JavaScript
Hello everyone. I have a question to the authors of this phorum.I really like the script that this site uses for image autoresizing.Can you please give me at least the name of this script cause i have been looking for something similar for some time now and still havent found anything. Thanks
Chillout Room
javascript problems
hi all iam having problems with my javascript. i go to youtube and get this message that my javascript is off or i need a newer version of flash player currently i dont have a anitvirus and have the popup blocker that my laptop came with. so i have the javascript on and i also unistalled and re...
Browsers & Mail

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 21:57.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App