Web Development: Selecting Elements from the DOM

Published on Apr 7, 2009   //  Development
Off

Web Development

Using the Document Object Model, we gain access to any elements that the webpage contains. Elements such as divs are suddenly at our full disposal. Today, I’m going to show you how to take control of these elements (first the elements, then the world! *evil laugh*).

We’re going to start out by selecting an element that has been assigned a specific id. Doing this will only return one element to us, as an id may only be used once. To do this, we’ll be using the getElementById(). With this function, if no element is found, it will return null. Let’s look at an example of where we select a div and change the text colour of it.

[code='javascript']document.getElementById('text').style.color = #CCCCCC;[/code]

Notice how Javascript and the DOM work in a nested manner. We start with the main document branch, then move down onto an element branch, creek our way onto the style branch and finally end up on the color twig. Envisioning the Document Object Model as a tree with branches (and branches on those branches, etc) is probably the easiest way to understand it.

The Document Object Model is very powerful, and understanding it will be key to getting a firm grasp on Javascript. If you don’t quite understand it, don’t fret, we’ll be continuing on with it for a couple more posts. You’ll have plenty of more chances to wrap your head around the concept.

PS: I’m attempting to keep my posts a bit shorter and focused on a single topic, in hopes of keeping more people’s attention. Let me know what you think.

Great Gadgets: The Messenger Bag Chair

Published on Apr 6, 2009   //  Gadgets

messengerchair

The sun is shining and the birds are singing. You know what that means! Spring is here and it’s about time that we are able to enjoy the great outdoors again, after being cooped up for months of a snowy and dreary winter. If you plan on heading out to the beach for a company barbecue, you may want to bring along a comfortable seat for use in between sessions of beach volleyball or frisbee toss.

Those regular foldable beach chairs can be a bit of a hassle to pack and they’re not all that fun to carry around from location to location. The crazy kooks at Hammacher Schlemmer have done it again with the arrival of the Messenger Bag Director’s Chair. In its closed form, this handy product looks like just about any other messenger bag. It looks like it would be suitable for students perhaps, or maybe for urban professionals who want a stylish way to transport for their laptops. Unfortunately, there’s no real storage here.

As its namesake implies, the Messenger Bag Director’s Chair is actually a chair in disguise. Fold it out and you’ve got yourself a great seat at the side of the barbecue. The bag itself weighs nine pounds and it can support people up to 250 pounds. If you happen to weigh more than that, this bag will provide even more motivation to drop a few pounds for the summer.

The Hammacher Schlemmer Messenger Bag Director’s Chair retails for $130. No one said that convenience would come cheap.

Weekend Projects: Favorite Icon

Published on Apr 4, 2009   //  Weekend Projects

Weekend Project

Last week we added a sitemap and submitted it to the top 3 search engines. This weekend we will focus on adding a favorite icon to our site. Whenever someone visits your site or saves it as a book mark your favorite icon is shown. The favorite icon can be a smaller version of your logo or a picture that will remind people of your site.

To start with you will need a favorite.ico file. There are a few software programs that can make them but they all cost money. A free solution is to use a free .ico generator where you can upload a picture click generate and it will allow you to download the favorite.ico to your local machine.

Now that you have a favorite.ico file upload it to your public_html folder.

Next you will need to add the following code to header of your index page on your site…

<link rel=”SHORTCUT ICON” href=”http://yourdomain.ca/favicon.ico” >

Be sure to replace yourdomain.ca with your own domain name. If you have various forums, blogs or sections of your sites you might want to have a different icon for each.

If you get stuck let me know in the comments.

Friday Funny

Published on Apr 3, 2009   //  Cartoon

Another cartoon created by creative genius  Matthew Schmoll. BlueFur Canuck
If you have an idea for a future comic or would like to submit your own BlueFur cartoon let us know in a comment.

In The Sphere: Ownership and Public Nudity

Published on Apr 3, 2009   //  In the Sphere

Did you manage to avoid the Rick Rolls of April Fools Day? Now that you’ve survived one of the trickiest days of the year, it’s time to take a more serious look at what the blogosphere has been doing this week. I’ve compiled another random mish-mash of posts that should address a wide range of interests. Including nudity. Read on to see what I mean!

Jennifer Mattern is working on a new magazine startup in the near future and she’s struggling to decide on the business model for the writers she will be hiring. Is it better, for all parties involved, to offer part ownership or up-front payments? The former gives the writers a vested interest in the venture, but the latter gives them an instant reward. What about from the point of view of the magazine?

Ewdison Then continues with the trend of publishing. As you may have heard, regular print-based newspapers are really having a hard time these days, since us many of us turn to the Internet for our news. How can they turn things around? It turns out that the majority of online journalists believe web advertisements will save the newspapers. Online ads are huge and can be a great revenue model for papers like the New York Times.

Consumerism Commentary has a very interesting perspective on how you can save a ton of money over the course of a lifetime. What is the number one frugality tip? Don’t be a woman. A recent study has revealed that the average “modern diva” will spend over $200,000 on her hair over a lifetime, bumping that up to a total of $450,000 when things like manicures, makeup, and facials are considered. And here I am complaining about an $18 haircut.

Ella Joe is a full-time working professional, but she has recently developed the urge to go back to school. She wants a shorter program, but more importantly, she wants to make sure that she’s actually interested in the subject. Among the shortlist are marketing, photography, and creative writing. We probably shouldn’t be surprised to see that algebra and calculus didn’t make the cut.

Mary Jaksch finishes off our weekly roundup with a healthy dose of public nudity. No, she’s not donning her birthday suit as she strolls through the mall, but she does ask us to consider the concept of the naked writer. With blogging, how much are we revealing to our readers? Are we confessing too much and allowing our blogs to get far too personal? Have you documented a recent breakup or battle with substance abuse?

Moving Beyond SSH: Cron Jobs

Published on Apr 2, 2009   //  Development
Off

Moving Beyond SSH

Last week, when we were talking about backups, I briefly mentions cron jobs. I would like to expand further upon cron jobs, as they can be very useful.

Cron jobs allow you to automatically run a script on a recurring schedule. Like we used them last week, they’re useful for script that will automatically backup your server. They’re also useful for performing repetitive tasks for you, saving you time and from having to remember to do them.

There are two ways we can setup a cron job. If you need a script to be run on a very simple schedule (hourly, daily, weekly or monthly), then we can just move our script to a special folder. For this method, there are four special folders that Linux creates. Any files in these folders will be executed on the schedule on which that folder is associated with. These folders are /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly and /etc/cron.monthly which correlate with the schedule of hourly, daily, weekly and monthly, respectively.

However, if you need to run your script on a more complicated schedule, you can also setup a cron job in a more manual manner. For this, we need to edit the /etc/crontab file. Each cron job should be on a separate line and have a syntax like this:

minute hour day month day-of-week user command

Here’s a break down of the values for these:

minute = 0-59
hour = 0-23 (0 is midnight)
day = 1-31
month = 1-12
day-of-week = 0-6 (sunday is 0)
user = The user this command should be run under
command = The command or file you want to be run

For each field, you may specify multiple values, separated by a comma. For every value except for user and command, an asterisks (*) may be used as a wildcard. This means that it will apply to every possible value. To further this, you can use a wildcard and a “step” to make it only apply to values divisible by a certain number. For example, */2 for the month field would be equivalent to 2,4,6,8,10,12.

So, at the point in time when all these conditions are met, the command will be run. Let’s look at an example for running a command every day at 4:32am.

32 4 * * * root /some/file

Then there we have it, a cron job. At some point in time, you’ll need to set up a cron job, and remember that you have two possible methods of doing so. Go forth and automate your repetitive (server-related) tasks!

Page 9 of 11« First...7891011