March 02, 2005

Automatic 'Print this page'

If you want to provide a way for the user to print the current page, include this little javascript snippet.

Of course, they could always just select file > print by themselves... but will they? A good combination is to use this in conjunction with the Javascript - Bookmark this page that is found elsewhere on this site.

This print function is also very useful when you are using frames. Since the browser doesn't always know which of the frames you want printed, and sometimes will only print the top frame you can use this to only send the data that the user will want printed. As long as you think you can predict WHICH of the frames they will want.

Since the javascript exists inside the frame, that's the one that'll be sent to the print que.

How do you do it? Put the following code somewhere on your page, again usually in the upper right.

< a href="#" onClick="window.print()" >Print this page< /a >

Try it next time you need or want to provide another feature on your site. As always though my advice is; don't overuse it!

Hope this helps.

Posted by kla3 at 02:36 PM | Comments (1) | TrackBack

URL Redirect

If a page on your site has moved, or your whole site for that matter, you will need to redirect your visitors automatically to a new page. Use this meta refresh to send them to the "new" page...

It's done with a "refresh" command using one of the META tags. Here is the piece of code you need to insert in the HEAD of your old page:


< META HTTP-EQUIV="refresh" content="0;URL=http://www.youraddress.edu/yourpage.htm">

Include anything in the BODY of the page if you choose. This is optional... if you choose 0 in the above example, no one will see it anyway. See below for more on this...

The content=" " command does two things. It tells the browser how many seconds to wait before executing the refresh, (the 0 here means zero seconds. If you want to, put in a number like 5 which will give the visitor enough time to read a message.) and then the url you want them to be redirected to.

Watch out for the correct placement of the quotes!. You're used to seeing the quotes around the url, but in this case, the quote marks are around the entire content=" " command, not around the number of seconds or url individually. They are separated by a single semicolon (;).

Of course, you are allowed to write whatever you need in your BODY section. In fact, it's a good idea to put some kind of message like this in case you have a user with an older browser. You should add a manual link to the new page inside the body section of your page:

< META HTTP-EQUIV="refresh" content="5;URL=http://www.youraddress.edu/yourpage.htm">

Then in the BODY tag, a simple text message similar to this:

***
This page has moved. If your browser does not automatically redirect you in a few seconds, click here to go to the new page.

Remember to change your bookmark, so you can find us!
***
As you can see from the example above, This message serves another purpose; it reminds the user to "bookmark" the new address.

One more detail, you might want to consider renaming the page something like:
< TITLE >We've moved!< /TITLE >

Hope this helps!

Posted by kla3 at 02:06 PM | Comments (1) | TrackBack

February 16, 2005

Javascript - 'Bookmark this page!'

Use this little javascript in your pages to enable the user to automatically "bookmark" your webpage.

Yes, I know, the feature is already available to anybody through the browser toolbar itself... but, by mentioning it on your page and creating this link, you draw attention to content that's deserving of a bookmark.

Here's how you do it. Place the following code somewhere in your page. It's a good idea to put this in the upper right so the user will see it upon entering the page. Make sure it's all on one line, no spaces except for the title of the page and the text on the screen.

< a href="javascript:window.external.AddFavorite
('http://blog.case.edu/webdev','Case Web Development Blog-Tips and Tricks')">Bookmark this page! < /a>

Change the text in the example to your own information and post this to an important page in your web presence. Maybe your homepage?

Hope this helps!

Posted by kla3 at 02:26 PM | Comments (1) | TrackBack