shortest incompatible script challenge

We all know that the interoperability situation on the Web has been abysmal. Web developers everywhere are vocally voicing their complaints of wasted time and money due to browser differences. Standards bodies that are meant to solve the interoperability problem become battle grounds of special interests, or create ivoryish spec-monsters that end up fragmenting the web even more. The dazzling bells and whistles of plugins threaten open standards..

So, let's have some incompatibility fun.

Here's a challenge for JavaScript-skilled readers: Who can come up with the shortest possible JavaScript that produces 4 different results in the top 4 engines?

(For the purpose of this exercise let's define the top 4 browsers as IE, Firefox, Safari/WebKit and Opera – latest available final versions).

The winner gets fame and fortune. (Well, I think I can afford a reward of ISK1000 these days if anyone is interested – certainly our friends in Iceland really need someone wanting to buy their money.. :p So the grand price is a souvenir 1000 krónar bill from Jon's country of origin.)

Ladies and gentlemen, post your answers in the comments.


26 thoughts on “shortest incompatible script challenge

  1. Before anyone asks, there are no rules. For example, you don't need to limit it to pure ECMAScript – the solution can involve the DOM, host objects, markup, CSS, anything. I suppose the code will be shorter if you don't but anything goes 🙂

  2. how about this:alert(navigator.userAgent)it does produce a different result everywhere, but it's a little too obvious :PEDIT: robbertbroersma beat me to the punch 🙂

  3. Event better:prompt(alert()) –>15 charsSafari: alert that reads "undefined", hit OK -> confirm box that reads "undefined" with blank input fieldFirefox: just doesn't runOpera: *blank* alert box, hit OK -> confirm box that reads "undefined" with blank input fieldIE: *blank* alert box, hit OK -> confirm box that reads "undefined" AND input field that contains the text "undefined"Just doing alert(), prompt(), and confirm() produces one (different) pair of browsers in each case that are the same, same with alert(alert()) unfortunately (or fortunately?).

  4. try{x}catch(e){alert(e)}Safari: ReferenceError: Can't find variable: xFirefox: ReferenceError: x is not definedOpera: <localhost>[Error:name: ReferenceErrormessage: Statement on line 2: Undefined variable: xBacktrace: Line 2 of inline#1 script in try{x}catch(e){alert(e)}]IE: [object Error]For reference:try{x}catch(e){alert(e)} –> 24 charsalert(navigator.userAgent) —> 26 charsalert(navigator.appName) —> 24 chars (but fails to be different in safari and ff)

  5. Not as short, but…(The first 2 are a stretch because 2 of the results for each appear to be the same to the user, but internally, they're different.)Focus the input and press del<input oninput="alert(1)">Opera: Fires the event twiceSafari: Fires the event onceFirefox: Doesn't fire the event because the value didn't changeIE: Doesn't support the input eventEnter a char in the textarea:<textarea oninput="alert(1)"></textarea>Opera: Fires the event twiceSafari: input is broken on textareasFirefox: Fires the event onceIE: Doesn't support the input event<script>var test = document.createElement("textarea");test.value = "nrnr";alert(encodeURIComponent(test.value));</script>Firefox: %0A%0D%0A%0DOpera: %0D%0A%0D%0A%0DSafari: %0A%0A%0AIE: %0D%0A%0D%0A

  6. for(;;)Konqueror/Linux: A script on this page is causing KHTML to freeze. If it continues to run, other application may become less responsive.nn Do you want to abort the script?Opera/Linux: Freezes the tab in some weird way, keyboard input is ignored, uses up one CPU core, other tabs and browser UI still workFirefox/Linux: Nothing appears to happenIE6/WinXP (German; sorry, I don't have anything else): Ein Skript auf dieser Seite verursacht eine Verzögerung in Internet Explorer. Falls das Skript weiter ausgeführt wird, verlängern sich die Antwortzeiten des Computers möglicherweise erheblichnnSoll das Skript abgebrochen werden? (I'm pretty sure it doesn't mention KHTML in the English version, so it's definitely a different response 😉 )Or, alternatively, if that counts:;Opera/Linux: shows Opera/Linux UIKonqueror/Linux: shows Konqueror/Linux UIFirefox/Linux: Shows Firefox/Linux UIIE6/WinXP: Shows IE6/WinXP UIor even the empty script, same result 😀

  7. <param><script>alert(document.getElementsByTagName("param")[0]);</script>Opera: object HTMLParamElementIE 8 beta 2: object HTMLUnknownElementFF 3: undefined (DOM isn't ready yet)Safari: undefined (params not inisde <object> are dropped by the parser and *never* make it to the DOM)

  8. alert(frames);// Opera: "[object WindowCollection]";// Firefox: "[object Window]";// Safari: "[object DOMWindow]";// IE: "[object]";

  9. navigator.appVersion

    LOL. This proves that it is possible to cheat even when there are no rules. Now since I get to be the judge I can probably cheat a bit too, make Opera mask as IE or Firefox and claim that two of the four engines do the same thing :-pI quite liked


    – an example so basic it's trivial.. :)Though it's long, I'll post this entry for its "huh?" value:

    <body onload="alert(typeof this.onload+typeof document.onload+typeof document.body.onload)">

    Opera: functionobjectfunctionIE (8, sorry): objectundefinedfunctionSafari: functionobjectobjectFirefox: functionundefinedundefinedHow many years have we had to deal with BODY onload=""? Pre-HTML4 stuff, right? Not two browsers do the same thing..More short'n'sweet peculiarities?

  10. hmm. I think the entries that rely on toString methods outputting different things for errors/dom objects are not within the spirit of the challenge. I do not think this constitutes a compatibility problem. I.e. nothing could possibly break because of that.

  11. For different *numeric* results in every browser, try this:var x=Date; alert(new x()/new x()/new x()/new x()/new x());It has also nothing with the core/engine functionality, but it works, though. 🙂

  12. //a in FF//does nothing in Safari//returns undefined in Opera//Dunno about IE but probably differentalert(/a/[-1])btw it sucks you have to register to comment :PNice blog though I read it all the time 😉

  13. x()Exception handling is a serious x-browser nightmare. This scratches the surface. Did I win?FF:message = x is not definedfileName = = 91stack = calc()@[object MouseEvent])@ = ReferenceErrorIE:name = TypeErrormessage = Object Expectednumber = -2146823281description = Object expectedSafari:message = Can't find variable: xline = 1sourceId = 39name = ReferenceErrorOpera:message = Statement on line 1: Undefined variable: xBacktrace: Line 1 of eval script x() Line 37 of inline#1 script in In function calc out.innerHTML = textToHtml(eval(expr).toString()); Line 18 of inline#1 script in In function once calc(); Line 1 of function script once() …opera#sourceloc = 1stacktrace = n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'

  14. Originally posted by garethheyes:


    Nice one – though it doesn't qualify for the competition because IE also says "undefined".I'm mystified by the Firefox response though. If it is a feature it looks like a very weird and quirky one, good catch!And I changed my prefs to allow anonymous comments, thanks for pointing it out :). If spam becomes a nuisance I'll have to change it again because I do NOT have time for comment moderation, unfortunately..Originally posted by drfe:


    Good attempt but if you look at the other entries they all contain code to make some sort of visible output. If you include a try..catch and on the error object's properties your entry isn't quite as short anymore ;). I admit to unclear requirements in the original post :p

  15. How do plugins threaten open standards? Most plugins for Firefox add to the browsers ui and don't actually touch the content. When they do its usually via a javascript, yet it has the ability to store local info and provide a nice ui to control it.

  16. Firefox "extensions" are a different type of plugin. "Plugin" in this context means something like Adobe's Flash and Acrobat Reader plugins, Microsoft's Silverlight and Windows Media Player and Apple's QuickTime. Their document- and application-formats sometimes compete with the HTML+JS+CSS set of technologies (e.g. when information is published in PDF format instead of HTML, when web applications are written in Flash instead of in HTML+JS..), and those who believe in the importance of open standards will claim this leads us to a more fragmented and less interoperable web.(To a certain extent those plugins are important because of the lack of good alternatives from the open standardisation processes – i.e. Flash video.)

  17. Anonymous writes:

    Wow, great post! Very interesting comments!I always had problems with the regular expressions across browsers. Now the holes are mostly patched up but generally each would do basic operations slightly differently when you tried to use regular expressions in them.Another thing I've had fun with is stylesheets. Try including some cross-domain javascript and then have that call document.write() to add a stylesheet. I know that you shouldn't do it but I have once or twice.After that put in some style elements sing actual markup and specify completely different and contradictory rules. I can't remeber the details but I remember a situation where Webkit would ignore the javascrpt CSS, Gecko would let you use it but also let you override it, Trident would not let you use CSS to override the javascript-included stylesheet, even if you used !important (or maybe because of it, you know IE. I'm talking back in IE6 here) and Opera would error out and pretend that there was no DOM available to javascript, and throw up some weird debugging alert error message.I can't provide example code because I've since learned what I was doing it wrong and how to do it properly (sorry)….I have had some great fun working across frames, too…(And if you're cheating with markup and using specific browser versions, try using non w3c dom in applciation/xhtml+xml. Each browser shows a different level of support for the actual javascript and IE simply spits the whole page right out because it is too pathetic to even display a well-formed web page from 1999)

  18. Анонимно writes:Have no enough money to buy a house? You not have to worry, because it's achievable to receive the loan to resolve such kind of problems. Thus get a bank loan to buy everything you want.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s