shortest incompatible script challenge
Friday, October 17, 2008 1:04:43 PM
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..
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.









Hallvord R. M. Steenhallvors # Friday, October 17, 2008 1:16:38 PM
robbertbroersma # Friday, October 17, 2008 1:46:47 PM
Daned4n3 # Friday, October 17, 2008 2:02:14 PM
alert(navigator.userAgent)
it does produce a different result everywhere, but it's a little too obvious
EDIT: robbertbroersma beat me to the punch
Kirilljarinkirill # Friday, October 17, 2008 2:03:51 PM
Daned4n3 # Friday, October 17, 2008 2:11:06 PM
Kirilljarinkirill # Friday, October 17, 2008 2:16:15 PM
Francisco iopossum # Friday, October 17, 2008 3:02:45 PM
Safari: ReferenceError: Can't find variable: x
Firefox: ReferenceError: x is not defined
Opera: <localhost>
[Error:
name: ReferenceError
message: Statement on line 2: Undefined variable: x
Backtrace:
Line 2 of inline#1 script in file://localhost/Users/tolmasky/Desktop/a.html
try{x}catch(e){alert(e)}
]
IE: [object Error]
For reference:
try{x}catch(e){alert(e)} --> 24 chars
alert(navigator.userAgent) ---> 26 chars
alert(navigator.appName) ---> 24 chars (but fails to be different in safari and ff)
Francisco iopossum # Friday, October 17, 2008 3:20:35 PM
prompt(alert()) -->15 chars
Safari: alert that reads "undefined", hit OK -> confirm box that reads "undefined" with blank input field
Firefox: just doesn't run
Opera: *blank* alert box, hit OK -> confirm box that reads "undefined" with blank input field
IE: *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?).
Mathias Plichtawrtlprnft # Friday, October 17, 2008 4:05:19 PM
Konqueror/Linux: A script on this page is causing KHTML to freeze. If it continues to run, other application may become less responsive.\n\n 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 work
Firefox/Linux: Nothing appears to happen
IE6/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 erheblich\n\nSoll 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 UI
Konqueror/Linux: shows Konqueror/Linux UI
Firefox/Linux: Shows Firefox/Linux UI
IE6/WinXP: Shows IE6/WinXP UI
or even the empty script, same result :D
Michael A. Puls IIburnout426 # Friday, October 17, 2008 4:54:14 PM
(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 twice
Safari: Fires the event once
Firefox: Doesn't fire the event because the value didn't change
IE: Doesn't support the input event
Enter a char in the textarea:
<textarea oninput="alert(1)"></textarea>
Opera: Fires the event twice
Safari: input is broken on textareas
Firefox: Fires the event once
IE: Doesn't support the input event
<script>
var test = document.createElement("textarea");
test.value = "\n\r\n\r";
alert(encodeURIComponent(test.value));
</script>
Firefox: %0A%0D%0A%0D
Opera: %0D%0A%0D%0A%0D
Safari: %0A%0A%0A
IE: %0D%0A%0D%0A
Michael A. Puls IIburnout426 # Friday, October 17, 2008 5:09:14 PM
<script>alert(document.getElementsByTagName("param")[0]);</script>
Opera: object HTMLParamElement
IE 8 beta 2: object HTMLUnknownElement
FF 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)
qwo # Friday, October 17, 2008 7:46:13 PM
// Opera: "[object WindowCollection]";
// Firefox: "[object Window]";
// Safari: "[object DOMWindow]";
// IE: "[object]";
temp1abc # Friday, October 17, 2008 11:10:01 PM
(same result as alert(frames))
qwo # Saturday, October 18, 2008 6:46:52 AM
alert(top) returns "[object Window]" in Opera and Firefox
Hallvord R. M. Steenhallvors # Saturday, October 18, 2008 8:23:33 PM
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 :-p
I quite liked
- an example so basic it's trivial..
Though it's long, I'll post this entry for its "huh?" value:
Opera: functionobjectfunction
IE (8, sorry): objectundefinedfunction
Safari: functionobjectobject
Firefox: functionundefinedundefined
How 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?
_Grey_ # Sunday, October 19, 2008 11:28:51 AM
Hallvord R. M. Steenhallvors # Sunday, October 19, 2008 10:14:57 PM
arantius # Monday, October 20, 2008 3:10:24 AM
19 bytes
IE6: no alert
FF3: semi-random small integer (see http://bit.ly/2cQMwB )
Opera 9.6: empty string
Safari 3.1: undefined
Less string cast trivialities, more real browser quirks.
pixycz # Monday, October 20, 2008 12:44:43 PM
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.
garethheyes # Tuesday, October 21, 2008 1:56:27 AM
//does nothing in Safari
//returns undefined in Opera
//Dunno about IE but probably different
alert(/a/[-1])
btw it sucks you have to register to comment
Nice blog though I read it all the time
drfe # Wednesday, October 22, 2008 5:20:38 AM
Exception handling is a serious x-browser nightmare. This scratches the surface. Did I win?
FF:
message = x is not defined
fileName = http://www.plexode.com/cgi-bin/eval.py
lineNumber = 91
stack = calc()@http://www.plexode.com/cgi-bin/eval.py:91
calc()@http://www.plexode.com/cgi-bin/eval.py:91
once()@http://www.plexode.com/cgi-bin/eval.py:72
onclick([object MouseEvent])@http://www.plexode.com/cgi-bin/eval.py:1
name = ReferenceError
IE:
name = TypeError
message = Object Expected
number = -2146823281
description = Object expected
Safari:
message = Can't find variable: x
line = 1
sourceId = 39
name = ReferenceError
Opera:
message = Statement on line 1: Undefined variable: x
Backtrace:
Line 1 of eval script
x()
Line 37 of inline#1 script in http://www.plexode.com/cgi-bin/eval.py: In function calc
out.innerHTML = textToHtml(eval(expr).toString());
Line 18 of inline#1 script in http://www.plexode.com/cgi-bin/eval.py: In function once
calc();
Line 1 of function script
once()
...
opera#sourceloc = 1
stacktrace = n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'
Hallvord R. M. Steenhallvors # Wednesday, October 22, 2008 2:54:25 PM
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
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 for..in on the error object's properties your entry isn't quite as short anymore
Jimtoyotabedzrock # Wednesday, December 17, 2008 8:09:04 AM
Hallvord R. M. Steenhallvors # Wednesday, December 17, 2008 6:26:27 PM
(To a certain extent those plugins are important because of the lack of good alternatives from the open standardisation processes - i.e. Flash video.)
Anonymous # Sunday, March 8, 2009 9:46:23 AM
Anonymous # Friday, April 22, 2011 8:58:18 AM