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

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

Windows 8.1 Professional x64
 
 

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

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

Windows 8.1 Professional x64
 
 

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

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

 JavaScript help...





Thread Tools



Similar help and support threads for2: JavaScript help...
Thread Forum
Javascript virus? System Security
IE9 - Problem with javascript Browsers & Mail
Help with Javascript? Chillout Room
Javascript error Browsers & Mail
javascript Chillout Room
JavaScript Chillout Room
Javascript error? BSOD Help and Support

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 08:53 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33