Randomize Web Images with JavaScript

This is documented in many other places on the Internet, but it can’t hurt to have too many tutorials. You can jazz up your web site with a bit of JavaScript to randomly insert images on your page. I’m doing this on my masthead, as one example. The first requirement is to build a list of images: Then write the code to select one at random: Finally, you need to set up the HTML to hold the image: The name=’myPic’ relates to the JS “document.myPic.src” declaration. The id=’frontphoto’ definition in the <img> tag is the CSS magic that sizes the image. And the ‘images/bg.gif’ is a placeholder image that gets… Read More

Continue Reading

De-clutter Your Rails Views, Use Partials For JavaScript SEO

If your Marketing or SEO guy is out of control (and when are they not?), you may be finding yourself stuffing insane amounts of JavaScript into your Rails views in order to track page referrals, conversion rates and other Google or Yahoo SEO analytic data. Not good from an esthetic standpoint. The solution is to use partials to partition the JavaScript SEO stuff off into a corner. Plus, it’s easier to reuse. Say you need to add some JS optimization code that looks like this: Just create a _google_opt_file1.html.erb file under app/views/shared and then call it in your view with This kind of SEO script typically goes right before the… Read More

Continue Reading