AJAX: What The Heck Is It?

Ajax is the new web 2.0 fad, and it is probably here to stay for quite some time. AJAX, or Asynchronous Javascript and XML, is a method used to communicate with the server and load new content in a website without having to reload the page. You’ve probably seen it all over the web, but possibly without necessarily thinking about what it is. The minor difference makes a huge positive impact on users, and a pretty negative impact on page impressions.

So what type of things would AJAX come in handy for? Well a very common implementation is for search tools. Say you are on a site looking for houses and there are tons of criteria you can enter in to narrow down your search. It is really helpful to see how each change in your criteria affects your results. To offer constant feedback, web developers need to use AJAX to bring back search results each time you change criteria. If they didn’t use AJAX, you’d be staring at a page reload every time, and that’d be mindbogglingly annoying…

A great example is a search tool I worked on at my company, College Prowler. The tool is meant for high school students trying to find colleges that fit their criteria of where they want to attend a college. Test it out and see for yourself here. The telltale sign of AJAX by the way is one of those circling gifs to indicate something is loading, so keep an eye out for that as you browse the web.

So now maybe you understand the benefits of AJAX. It makes for a much more fun and usable experience for users as they traverse your website. The serious downside is a decrease in your pageviews. Every time you make an AJAX call, you lose what would have been a new page load and thus a new pageview. With each pageview (if you know what’s good for you AND have a highly trafficked website), you gain ad income. Now you could argue that with the improved user experience, you’ll make up for the lost pageviews in your AJAX tool with more devoted users (an argument I agree with), but that doesn’t cut it for everyone.

So make the choice to go with AJAX. In an upcoming post, I’ll write about the basics of AJAX and how to implement it.
Cheerio!

HTML For Beginners

I’ve been inspired to write an explanation of how HTML works, and how webpages are created in general, so that the average person, computer-savvy or not, can understand, and even do their own work with HTML. But, I’m gonna start at the WAY beginning, so if you already sorta get it, then don’t start here.

So first, an explanation of what HTML is. HTML is what us web designers and developers use to tell a person’s internet browser how to make the webpage look. How about an analogy. Say you just painted a room in your house, and to do it, you took everything out of the room and put it in a pile. Now you need to put all the stuff back into the room, all in a specific place. Certain things need to look certain ways. Pictures need to be hung on the wall, furniture needs to be up against the wall, books need to be on shelves, and lamps need to be plugged in. Now think of the webpage as the room, and all the things you have to put in your room are the pictures and text and links you want in your webpage. All those different things have to look certain ways, and for a person’s browser to know where to put everything on the page, it needs HTML to explain it.

Let’s get a bit more specific. Every webpage you ever look at has HTML in it. The basis of HTML is something called a tag. The tag is what you put around different types of things on your webpage so the internet browser knows what to make it look like. There is a tag for paragraphs, for images, and for links, in fact there are about 100 different types of tags (Here’s a list of all HTML tags). Really, only about 20 are commonly used though, so don’t worry. All tags look something like this (but for the example, this is a paragraph tag):

<p>Your paragraph goes inside here.</p>

You’ll notice the paragraph tag opens, then you put in the paragraph, and then it closes with the slash you see above. You can also put tags inside of other tags. In fact, that is really the basis of all HTML pages. Say for example you wanted a link inside of your paragraph. You’ll obviously have a link tag inside your paragraph tag. That would look like this:

<p>Your paragraph goes inside here. And here is a <a href="www.google.com">link</a></p>

The a means a link, and href is where you put the destination of the link. Similarly, images are put into tags. Images have the img at the beginning for image, then the source (src) where the image is (if you copy and paste that url into your browser, you’ll visit a page with just the image), then the height and width of the image (in pixels), and then alternative text (alt) if the image doesn’t display.

<img src="http://www.davidjrush.com/images/tutorials/stickyFooter.gif" height="251" width="351" alt="Sticky Footer Tutorial" />

Now you’ll notice that there is no closing tag for the img tag, because nothing goes “inside” of it. So, it closes itself at the end with a slash.

Some other common tags you’ll see, and what they mean:

<html></html> <!--The entire HTML page is wrapped inside an html tag-->
<head></head> <!--Things like the title and description of the page go in the head tag-->
<body></body> <!--The body tag contains all the displayed HTML-->
<table><tr><td></td></tr></table> <!--This is a table like in Microsoft Excel. First you open the table, then you have as many rows as you want (tr) with as many columns as you want in each row (td).-->
<ul><li></li></ul> <!--This is an unordered list (ul) with lots of list items in it (li). Unordered lists have bullets. Ordered lists (ol) have numbers.-->
<h1></h1> <!--This is a header tag. Titles and bigger text go in here. There are 6 header tags that display smaller as you increase the number (h2, h3, h4, h5, and h6).-->
<div></div> <!--Think of the div tag as a two-dimensional box. You can put stuff in it, tell it how big to be, and tell it where to show up on the webpage. This is probably one of the most common HTML tags, and also the hardest one to understand.-->

Alright, that’s enough of those for now, because those are the major ones. Browsers have default ways of displaying those tags. Then, what web designers do, is they apply special rules to those tags so they display just how they want them to. That’s what makes different websites look so different! Those special styles are included in different files called CSS files, or Cascading Style Sheets. I’ve written many posts on CSS, here’s the CSS Back To Basics post. Any questions, feel free to ask! And if you are ever curious how a webpage is written, you can go to your browser, click the view menu, and select to view the source. That will let you see all the HTML that makes the page you are viewing! Don’t get overwhelmed though, just give it a shot and take your time.

Take a Stand: No More IE6!

It is time for the web design community to take a stand and stop supporting Microsoft Internet Explorer 6! That’s right, I said it, as many have said before me, and yet somehow, most web designers still cross-browser test in IE6. Well, guess what, I’ve stopped. Okay, not completely. With my freelance clients, I will probably still check IE6, because truthfully, many of my clients themselves still run IE6. However, at my fulltime job as the web designer for College Prowler we have officially stopped supporting IE6! So why did I push for this, and how are we handling it?

So, some quick stats on Microsoft Internet Explorer 6. IE6 was launched by Microsoft in 2001. Though it has had some minor updates since it’s initial launch, you know that doesn’t change anything, especially because some people out there are still using that first launched version! IE6 came standard on every Windows machine since then until IE7 was launched in 2006. Now last time I checked (aka when this post was written) it was late 2009. IE6 has been out of date since it’s inception, but has definitely been out of date since it was replaced by IE7 over 3 years ago. So how it is that still approximately 5% of internet users still use IE6? Well sadly, Microsoft does not require, or even really push users to update, especially in the olden days. I grabbed that 5% estimate off of Google Analytics for my own site, College Prowler, and a few of my freelance clients. Though the percent is slowly falling, it will be around for a while I’m sure. So, based off of the small percentage, which is slowly falling, and the fact that cross-browser testing IE6 occupies at least 50% of my cross-browser testing time

The irony of it all is that even Microsoft is desperate for users to upgrade off of IE6 to IE7 or IE8. This of course begs the question, how stupid do you have to be to still run IE6!?! At least 90% of the display bugs I’m aware of are solely IE6 problems. Entire blog articles are devoted to listing bug fixes for IE6. Well, based off of all of those stats, our company finally let me move away from IE6. We put up a warning (only visible to IE6 users) that we don’t support IE6. We even included a link to download IE8, but somehow I don’t think that’s gonna do anything. I’m just glad to be done with it!

So if you know what’s good for you as a web designer, forget IE6! The more people that stop supporting it, the faster people will switch off of it, and the faster we’ll be rid of that evil browser that has trouble outputting today’s beautiful websites. Of course, if you are still making websites with red text on a blue background, maybe you should still be testing in IE6…

PHP – Header and Footer Templates

Why use PHP header and footer templates? Luckily, there is a very simple answer to this question. When you need to change a piece of navigation, or an image such as your logo, or even just change the copyright year in your footer, do you want to have to go into every HTML file to change that one item? Of course not! Using a php header and footer will allow you to avoid changing all of your pages, and instead only make you change it once!

So how does it work? Simple. There are a few catches though first which you might not like, so pay attention! First, your website URLs will now end in .php instead of .html. Second, you won’t be able to test your website without using a server that can compile your PHP. As I explained in a previous post, PHP – What Is It Good For?, PHP is a server side language, as opposed to HTML, CSS, or Javascript, which are all client side languages. Client side languages are read and interpreted by an individual person’s browser, whereas server side languages are read and interpreted by the server that hosts the website before it arrives back to the individual user. Easy solutions are to either put it up live to test it (not advised), or to install an Apache server on your computer, which wasn’t the easiest thing for me to do (because I’m not very techy) but there are some good walk-throughs out there, and the software is free. I use it all the time now because I do all my sites in PHP.

But I’m not a web developer, I’m a web designer! Don’t be intimidated if you aren’t a programmer. Writing websites in php can be as little as 1% PHP and 99% HTML/CSS. I didn’t realize this until I actually tried to learn it, at which point I was much more comforted. You still make your entire site using your HTML or CSS, the PHP just decides essentially what content to put in where after you’ve made it all using your HTML/CSS.

How do I implement it? Alright, now here is your explanation. You’ll need 3 total files. One called “header.php”, one called “footer.php”, and one called “index.php”. Inside your header file, cut and paste all the header code (starting all the way at your opening html tag or doctype declaration if you have one… because you should). Then, do the same for your footer file with your footer HTML. Now, inside of your index.php file write two lines of code, one at the top, and one at the bottom, you can probably guess which goes where:

<?php include("header.php"); ?>
<?php include("footer.php"); ?>

And that’s it, run it on a server and you are set. Still a little confused? Well here, this is what each of your files should look like:

header.php

<html>
  <body>
    <div class="header">
      Logo, navigation, et cetera goes in here
    </div>

index.php

<?php include("header.php"); ?>
    <div class="mainContent">
      <h1>Header in here</h1>
      <p>Paragraph in here</p>
    </div>
<?php include("footer.php"); ?>

footer.php

    <div class="footer">
      Footer content goes in here
    </div>
  </body>
</html>

And that’s it, got any questions, ask away!

Javascript: Rollover Dropdown Menus

Up until recently I’d never implemented a rollover dropdown menu. Then I just decided to build one from scratch for my employer College Prowler to improve upper-level navigation. Basically, with some simple javascript to hide/show the menu and some CSS to style and position it, you’ve got yourself a simple javascript rollover dropdown menu! The code follows the example implementation below.

The Javascript:

function rolloverMenu(showHide, menu)
{
    var link = 'mainLink';
    if (showHide == 0)
    {
        document.getElementById(menu).style.display = 'none';
        document.getElementById(link).setAttribute('class', 'mainNav');
        document.getElementById(link).setAttribute('className', 'mainNav');
    }
    else
    {
        document.getElementById(menu).style.display = 'block';
        document.getElementById(link).setAttribute('class', 'selectedRollover');
        document.getElementById(link).setAttribute('className', 'selectedRollover');
    }
}

This javascript will either hide or show the menu depending on the location of the cursor. The HTML that calls the javascript has a delay on it as well, but you’ll see that later. This javascript also changes the class name of the link so that even though your mouse isn’t technically hovering over that link it will look like it is being hovered over.

The CSS:

#container{
    position: absolute;
    z-index: 1001;
}
a.mainNav{
    color: White;
    font-weight: bold;
    font-size: 12px;
    height: 40px;
    padding: 0px 10px;
    line-height: 40px;
    float: left;
    background-color: #1D3E66;
}
a.mainNav:hover{
    background-color: #3D6199;
    color: #AAAAAA;
}
a.selectedRollover{
    color: White;
    font-weight: bold;
    font-size: 12px;
    height: 40px;
    padding: 0px 10px;
    line-height: 40px;
    float: left;
    background-color: #3D6199;
}
.rolloverMenu{
    float:left;
    padding: 10px 10px 6px 10px;
    position: absolute;
    z-index: 1000;
    background-color: #3D6199;
    width: 100px;
}
.rolloverMenu#mainMenu{
    top: 40px;
}
.rolloverMenu a{
    color: White;
    font-weight: bold;
    font-size: 12px;
    line-height: 20px;
}

Change the CSS to fit your own design. I’ve been very specific in this CSS so that it should be easier for you to identify everything. Note that the #container definition is actually very important for an IE6 bug fix. IE6 has issues with z-index when not combined with absolute positioning. Basically, the parent element of the rollover menu needs to have that specific definition.

Lastly, the HTML:

<div id="container">
  <a class="mainNav" href="#" id="mainLink" onmouseover="rolloverMenu(1, 'mainMenu');" onmouseout="rolloverMenu(0, 'mainMenu');">Rollover Me</a>
  <div class="rolloverMenu" id="mainMenu" style="display: none;" onmouseover="rolloverMenu(1, 'mainMenu');" onmouseout="rolloverMenu(0, 'mainMenu');">
    <a href="#">Link 1</a><br />
    <a href="#">Link 2</a><br />
    <a href="#">Link 3</a><br />
    <a href="#">Link 4</a>
  </div>
</div>

And that’s that! The HTML link calls the javascript which implements a series of CSS rules that will hide or show the menu of your choice! Have fun!