What I did on my vacation from reality

Home About RTL8187B Laptop Cam Quotes Login

October 4, 2008

Fun with Javascript

3:03 pm — Code, Main, Misc

I made a few improvements to the site. (Yes, I know those Javascript popups from you people trying to download the RTL8187B drivers while I was trying to debug were probably pretty god damn annoying. Sorry. I set up a testbed on my laptop so I won’t have to debug here any more.)

One of the neater things I came across was Lightbox, which is a really spiffy image viewer. The real fun came when I decided that I didn’t want the image actually rendering anywhere on the page. :-) Easy enough, and two ways to do it. The first is to write an anchor tag (with foodocument.createElement(’a')) and setting its style.display to “none”. (Make sure you set all the other attributes, also. The most important are rel="lightbox" and href="whatever image you’re displaying.) Then just have your script call myLightbox.start(foo) when your conditions are met and you want it to display the image.

The other way to do it is to actually write out all the HTML manually: e.g., <a href="/~cuervo/goatse/goatse/hello.jpg" rel="lightbox" id="goatseLink" style="display: none;"></a> <a href="javascript:myLightbox.start('goatseLink')">Open wide!</a>

Obviously, you can use whatever you want instead of an anchor tag pointing to myLightbox.start().

Another thing I was playing around with (mostly for the sake of relieving boredom, and because I hadn’t done it in a while) was AJAX, loading HTML into the page with another HTTP request after the page had already loaded. While I was doing that, it occured to me that it would make a good anti-spam technique: if you’ll notice, spam bots tend not to know about Javascript. It’s a pretty commonly proposed way to obfuscate addresses (although I’ve never seen it done, but I might have just not been paying close enough attention).

Anyway, here’s some Javascript to make life easy, mostly the usual muck with a few extra lines. Just load it in, create an HTML element with id="divName, then call ajaxSetDiv('divName‘, ‘some URL‘); and the rest takes care of itself.




RSS feed | Trackback URI

Comments»

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.