TechBlog
leaflet
#js1k entry finally complete - AsciiBrot1K:http://urlm.in/flii - from T-SQL to JavaScript and then down to just 1KB of hand-compressed code

Slightly Stricter Scripter

Posted on 6 August, 2008 by maximinus in JavaScript, Web development
A while back, I started writing a web app, which still hasn't quite made it to public availability - but which I use myself, even in its incomplete state.  I knew as of the first public beta of Firefox 3 that this app didn't seem to work at all in Firefox 3 - but I was never terribly bothered about why.

Tonight, I decided that it was finally time (since I now use Firefox 3 on my laptop, desktop PC and work PC) to investigate the cause of the problem.  For some reason, nothing was rendering at all once I logged in to the app - I was left with a white page.  There's some static HTML content which should have been displaying, even if there had been JavaScript errors - which Firebug reported none of.

I started using Firebug to poke around, and I noticed that the static HTML content was indeed being returned in the HTTP response - but for some reason was not being rendered.  I looked a little more closely, and noticed that I'd been lazy with one of my script tags, and closed it as a one-sided tag (<script src="..." type="text/javascript" />) - which is technically invalid, but Firefox 1.5 and 2, Opera and even IE6 (I haven't actually tried it in IE7) didn't seem to have a problem with.  Firefox 3, on the other hand, handles this error in a rather odd (and annoying) manner: it eats the rest of the page content.

What I mean by this is that the page content totally disappears from the DOM - it appears that it first treats everything which follows the malformed script tag as the tag's body - but then downloads the external .js file and replaces the tag's body with its contents, thus losing the rest of the page.  If, like in my case, the malformed script tag is in the <head> section of the page, you'll simply get a white screen, since the entirety of the <body> section is lost in this way - along with any onload events defined in the opening <body> tag (hence the lack of JS errors).
Currently listening to: Coldplay - White Shadows
No comments have been posted on this entry. Click here to post a comment.

POSTing cfajaxproxy

Posted on 1 April, 2008 by maximinus in JavaScript, Web development
On a similar tack to the URL length limit mentioned in my post about the moonwalking kiwi, today I discovered a minor issue with cfajaxproxy, along with the (very simple) solution.

By default, cfajaxproxy will use HTTP GET requests to interface with the server, which is all fine and dandy if you're just passing in an ID or two to the function, and expecting data back from the server.  However, if you're using the proxy to send data back to the server, you'll probably want to set the proxy to use POST rather than GET - otherwise you run into length limits related not only to the browser (and its XmlHttpRequest object), but of the webserver.  IIS in particular seems to have a lovely habit of returning cryptic 500 errors complaining about bad verbs.

As I said, once you've found out how to do it, it's very simple to make a proxy use POST.  Once you've created the proxy class using the <cfajaxproxy> tag, you instantiate it as per usual, and then use its setHTTPMethod function:
<cfajaxproxy cfc="yourapp.cfcs.bar" jsclassname="Bar">
<script type="text/javascript">
var foo=new Bar();
foo.setHTTPMethod('POST');
</script>
You can then proceed to use the object ('foo' in the example above) as before, without having to worry about exceeding the URL length limit(s).
No comments have been posted on this entry. Click here to post a comment.

Moonwalk

Posted on 19 February, 2008 by maximinus in JavaScript, Web design, Web development
It's not all fun and games in web development.  Sometimes, clients request odd things, such as redirecting the domain name for a defunct Japanese site of theirs to another Japanese website.  We were given the URL to redirect to; upon clicking through to the site, we discovered that it was an equally dated site; not only are some of the links broken on certain pages, but there's an animated GIF of a kiwi in the corner of the site.

One of my colleagues pointed out that it looked as if the kiwi was moonwalking on the spot.  This gave me an idea to liven up the site - make the kiwi actually moonwalk across the page header.

Of course, not being one of our sites, we don't have access to the files, so I can't make it permanently happen.  What I can do, though, is use a javascript: address in the address bar to play around with the page once it's loaded.  622B 577B 477B 494B of JavaScript later, I have a moonwalking kiwi:
  1. Visit the site, and wait for it to finish loading.
  2. Grab the moonwalk JavaScript, paste it into your address bar (making sure it's all on one line) and hit enter.
  3. Enjoy.
You may have noticed that there are two three crossed-out sizes; I decided to do a bit of optimisation and refactoring, bringing it down to 577B, then thought that while I was at it, I may as well tackle the IE issue.  This is where I discovered something odd:
Internet Explorer 6 will only allow 501 characters in the address bar before it fails.  It fails silently if you exceed this limit.  As a result of this, I started shrinking the code as much as possible, which involved a bit of code golf with a few guys in an IRC channel - we decided to call this "JavaScript Hack Minigolf."  The end result was a lean 477 characters.  I also worked out what was happening in Opera - the version I've got installed (9.02) appears to, at least by default on Windows, stop the script running after a set period and return things to their initial status.  It's apparently fine in 9.24 on Linux, though.  I've now discovered that IE wasn't aligning the inserted div properly, and the fix has now brought it back up to 494 characters - thankfully still within IE6's limit.  I've also found that IE7 doesn't have the 501-character limit (I haven't checked if there's a higher limit or no limit).

Thanks to Arachnid for playing a round of JSH Minigolf with me, and to Pic, silentcoder, langly and warfreak2 for their moral support.
Currently feeling: Devious
Currently listening to: Roads - Roadrunner United
No comments have been posted on this entry. Click here to post a comment.

New ShrinkThisLink Site Live!

Posted on 15 July, 2007 by maximinus in PHP, JavaScript, Web design, Web development
Finally, after months of on-and-off work, the new ShrinkThisLink site has gone live.  It features a new design, AJAX shrinking of links, instant link conversion using Javascript, an improved My ShrunkLinks feature (including link deletion) and more.  Hope you like it - your feedback is appreciated, either via comments on this blog post or by email (use the Contact link on ShrinkThisLink).
Currently feeling: Relieved
No comments have been posted on this entry. Click here to post a comment.

Web Design Woes

Posted on 30 December, 2005 by maximinus in JavaScript, Web design, Rant
So, I'm sitting here working on the long-overdue next version of BLISS, the blogging engine which powers Rant of the Day, and I am, as per usual, battling to try to make things cross-browser compatible.

This time, however, through a cruel twist of fate, it's not IE which is 'misbehaving' as such - this time, it's the only browser which supports CSS which lets me do what I want. This is because MS have extended CSS to do these things - but they either haven't reccomended them for inclusion in the official CSS spec (thus allowing for cross-browser support) or they have, but too late to make a current CSS spec.

I can't even seem to find any nifty JavaScript snippets or anything that'll do the job instead. It seems that truncation other than at a set number of characters is just one of those things which is near-impossible.
No comments have been posted on this entry. Click here to post a comment.