Arrow

Posts on this site are never sponsored.

Hide text on a webpage for printing (CSS), use JavaScript to make a variable-sized textarea

OK, this is old to most, but new to me! Normally I loathe working with CSS (Cascading Style Sheets), but this time it provided me with a quick solution to my very problem.

So here’s the situation. You have some user-generated form output and you want to allow users to add some custom text for printing. This text needs to have a variable size. To do that, you can use JavaScript to give users the option to vary the size of a textarea.

Screenshot of variable-sized textarea

See this page for a working example.

However, when a user prints the page, you want to hide “show X header rows for printing” and probably want to remove the borders around that header. To remove the borders, all you have to do is redefine the CSS styling for print (apparently this has been built in to CSS for quite some time… nobody told me!). So, if your normal CSS code was like this…

#customheader {
border: 1px solid black;
}

… just add some code to override the definition for print:

#customheader {
border: 1px solid black;
}
@media print {
#customheader {
border: 0;
}
}

Similarly, if you stuck the “show X header rows for printing” in a DIV called “hideforprint”, use the CSS code “display:none;” to, well, hide it for print, like so:

@media print {
.hideforprint {
display:none;
}
}

An alternative to using “@media” to only override certain styles is to define the media type in the style tag:

<style type="text/css" media="screen">
Put all your normal CSS stuff here
</style>

<style type="text/css" media="print">
Completely change the look of the document for print here
</style>

If you go back to my example page, you can view the entire source code that I just tried to awkwardly describe.

Download The Corporation for free (guilt-free, too)

I used to download movies before my conscience got the better of me. But here’s a movie that anybody can download guilt-free…

The filmmakers of The Corporation (from BC!) have released an official “Download Edition” of the movie (the full movie in high quality DivX format), available as a torrent. Read about it here.

If you’re unfamiliar with torrents, download a client such as μTorrent and then click on a link to a torrent file. Torrents are a form of peer-to-peer sharing somewhat similar to what Napster was doing.

I’ve also posted the “read me” PDF that comes with the torrent.

I saw this movie in theatres a few years back and absolutely loved it. It examines how the concept of a corporation has developed into the psychotic excuse for immorality that it is today. It’s what I would call an almost-documentary (whatever that means). The movie managed to take what might seem to be a boring topic and make it thought-provoking and entertaining.

You can also donate some money to the filmmakers on their website if you appreciate the film.

Open PDFs in your browser (well, Firefox) faster

I dread opening PDFs in my browser. They’re so slow to load (with Adobe Acrobat and Reader) and sometimes they even crash my browser. This is even more painful when in Firefox (which I otherwise love), with several tabs open at once.

Well, if you are in the same boat, say goodbye to this problem. It can be solved quite simply by 1) using Foxit Reader as your default PDF reader; and 2) not opening PDFs in your browser to being with.

1) Why Foxit? It’s small, resource-light, and loads quickly. That’s all you need to know, really. Anyway, download Foxit here.

2) To stop opening PDFs in Firefox, click Tools… Options. Then, select the Downloads tab. Then, click View & Edit actions… Then, find the row for PDF and click Change Action… Finally, select Foxit as the designated application:

The fastest PDF reader

There’s a way to do this in Internet Explorer too, but I’ll leave that up to you!

So far, programs with “fox” in their name are quite good.

Clear, simple outlined map of Canada

I couldn’t find a plain, large map of Canada to add my own comments / locations to, so I stole this one, removed all the colour, and thickened the lines.

Click on the image below to view/download the huge 2099 x 1845 pixels (415KB!) version.

Plain map of Canada with clear outlines

——————————-

Here’s one of the Lower Mainland, stolen from this site.

Click on the image below to view/download the bigger 1675 x 596 pixels version.

Plain map of the Lower Mainland with clear outlines

Improve your Captcha anti-spam efforts

My anti-spam plugin is one of many Captcha comment plugins for WordPress. In the effort of continuous improvement, I’m perpetually trying to tweak my plugin for better performance, effectiveness, and compatibility. Here are two points that are problematic for most of the Captchas and that might be helpful for other amateur developers like me.

1. Use the preprocess_comment filter to analyze comments early
Thanks to the ever-so-detailed WordPress Plugin API I discovered the filter preprocess_comment, which is the first “event” that occurs when a comment is posted. Most plugins call their functions during the action comment_post, but this “event” occurs a bit too late in the timeline. While comment_post is occuring, the comment has already been posted to the database, and your plugin is forced to go into the database to delete spam comments. This is obviously transparent to users, but is ineffecient from the processing point of view.

What you should try to do is to stop the spam before it hits the database by using preprocess_comment instead of comment_post.

2. Give users the option to allow trackbacks and pingbacks through
Captcha forces users to enter the characters seen in an image in order to ensure that the poster is not a spambot. However, trackbacks and pingbacks are other ways of posting comments, and they obviously cannot see your Captcha image. You can use other methods of stopping trackback and pingback spam, such as installing a filter-type plugin (for example, Akismet) or renaming your trackback file. But the problem remains that you have to correctly identify trackbacks and pingbacks in order to turn off the Captcha test. Otherwise, users that install your plugin are effectively blocking all trackbacks and pingbacks.

Surprisingly, the answer to this problem was a bit hard to find, but it turned out to be quite a simple solution. In the array that is sent during the preprocess_comment event, one of the fields that is submitted is comment_type. The value of this is blank for normal comments, and is otherwise equal to “pingback” and “trackback”. Therefore, use an “if” statement such as the one below (in your comment filter function), in order to identify and subsequent allow the passing through of pingbacks and trackbacks.

if ($incoming_comment['comment_type'] == "") {
// run anti-spam check }
else {
// return to normal }

————————————–

Thanks to Ajay for taking the time to examine some of this stuff with me.