demosthenes.info

I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter or add me on Google+.

web developer guide

my books

Book cover of Pro CSS3 AnimationPro CSS3 Animation, Apress, 2013

my projects

tipster.ioAutomatically provides local tipping customs and percentages for services anywhere.

Printing Information To The Screen With JavaScript

javascript / introduction

Estimated. reading time: 3 minutes, 43 seconds

As a general course of study in web development, I recommend learning , , , then . It’s very easy to print something to the browser window in the first three languages: in PHP, one typically uses echo, print, printf, or a similar function. You can use echo exactly where you want the information to be shown on the page:

<p><?php echo $var ?>

It’s not always clear how to accomplish the same in JavaScript. The simplest option, and the one most similar to echo, is also the least recommended: document.write

<p>It’s easy to write information to the screen <script>document.write("with JavaScript");</script>

This “inline” JavaScript is inserted exactly where you want the new information to be added. There’s also the closely related document.writeln, which adds a newline character after the insert.

Build Better Text Extracts With PHP

php

Estimated. reading time: 1 minute, 48 seconds

Many developers spend time writing code designed to extract a very specific number of words or characters from a piece of text. This text sample, often drawn from a blog post or comment, is usually displayed with a link that leads the user to read more.  You can see an example on this site in the extracts of articles added to favorites in user profile pages.

Using a thoroughly organized content management schema that divides every article into a lede, nut graph, and body units of text minimizes the need for string manipulation. However, such units are not always available or applicable.

It’s possible to use , and server-side languages to create text extracts. For the purposes of this article, I’ll use .

Photograph of twins sitting back-to-back, taken from above

matchMedia: Media Queries For JavaScript

mobile

Estimated. reading time: 3 minutes, 3 seconds

Many developers associate exclusively with , but the reality is that every web technology has a role to play in optimizing sites for devices. In some cases, there are functionally equivalent features across different languages that allow you to choose the most appropriate tool for a particular set of conditions.

matchMedia is one such feature, allowing CSS3 media queries to be tested directly within . The syntax couldn’t be easier: