Javascript: What is the standard?

I've recently been writing a little javascript, and I needed to chage the value of some text inside an html/xhtml element. It seems there are several ways to do this, but evey browser may or may not support the same method for doing it (big surprise, here) I'm not sure what is considered the "standard" way. Here's a little script that I use to help me decide which browsers support which methods for altering text within an html/xhtml element:

<html>
<head><title>blah</title>
<script language="JavaScript">
<!-- Hide code from older browsers
function loader() {
pp = document.getElementsByTagName("p")
pp[0].innerText = ".innerText DOES work!"
pp[1].style.content = ".style.content DOES work!"
pp[2].innerhtml = ".innerhtml DOES work!"
pp[3].childNodes[0].nodeValue = ".childNodes[0].nodeValue DOES work!"
}
// End hiding-->
</script>
</head>

<body onload="loader()">
<h1>Changing text with javascript</h1>
<p> .innerText DOES NOT work.</p>

<p> .style.content DOES NOT work.</p>
<p> .innerhtml DOES NOT work.</p>
<p> .childNodes[0].nodeValue DOES NOT work.</p>
</body>

</html>

(Thanks to the users of codingforums.com, especially Roy Gardiner, whose code from which this script was adapted.)

magic SysRq

Occasionally I goof up. Yes, as much as I hate to admit it, it's true. However, thanks to this handy tutorial on liquidweather.net, I've learned about some nifty ways to kill things in linux.

In addition to the traditional ways to kill a process, this tutorial lists some magic SysRq key combinations that--if enabled in your kernel--can provide a nice option to just pulling the plug...
  • Alt+SysRq+K - Kills all processes (SIGKILL / kill -9)

  • Alt+SysRq+E - Terminates all processes (SIGTERM / kill -15)

  • Alt+SysRq+I - Interrupts all processes (SIGINT / kill -2)

  • Alt+SysRq+U - Force unmount and remount of all filesystems readonly

  • Alt+SysRq+S - Syncs all disks

  • Alt+SysRq+B - Reboots

(Note to self, and any other developers: When using a language without built-in garbage collection, don't forget to free up memory when you're done!)

wifit - an iwconfig tool

I've recently installed Mepis Linux on a couple of laptops (a Compaq Presario 2195US and a Dell Latitude D610, both of which use NdisWrapper for wifi drivers).I'm fairly mobile, so I needed a way to quickly change my wireless settings. I wrote this simple bash script to let me do that, and I thought I'd just share it.

#!/bin/bash

## wifit - the wifi tool
## This is a script that accepts a wifi-enabled interface,
## essid, and an optional ascii key for a wifi network connection

if [ $# -lt 2 ] || [ $# -gt 3 ] ; then
echo "wifit - the wifi tool"
echo "-------------------------------------------------"
echo "Usage: wifit [Optional: ]"
echo " Example: wifit wlan0 somenet "
echo " Example: wifit wlan0 somenet mypassword "
echo "-------------------------------------------------"
else
echo "Setting up wifi connection for "
echo "Interface $1, ESSID: $2..."

iwconfig $1 essid $2
iwlist $1 scan
iwconfig $1 mode Managed
if [ -n $3 ] ; then
iwconfig $1 key restricted s:$3
else
iwconfig $1 key open
iwconfig ap any
fi
iwconfig commit
dhclient
fi

To use this, just copy and paste the code above into a file named wifit (or wifit.sh, or whatever you want). You'll then need to make that file executable using chmod:
chmod a+x wifit.sh
Then, simply call the script (possibly using sudo) passing it any arguments you need:
sudo ./wifit wlan0 somenetwork

Alternatively, you could place this file in your /usr/local/bin or /usr/bin directories so that it would be included in your PATH. If you find this useful, or if you decide to add to is, feel free to Contact Me!

Enjoy.