JavaScript speeding ticket
Wednesday, 15. November 2006, 13:18:44
Says the famous Orkut if you try searching your friends:
<form method="POST" action="/Friends.aspx">
<input id="searchMyFriends"
onkeypress="if ((window.event ? event.keyCode : event.which) == 13) { handleDoSearch(); }"/>(irrelevant HTML removed)
The handleDoSearch function does this:
function handleDoSearch() {
var url = '/Friends.aspx';
url += "?show=search&searchQuery=";
url += encodeURI(document.getElementById('searchMyFriends').value);
document.location = url;
}When you type something into the "search my friends" box you are supposed to press enter to start the search. (I guess they don't worry about computer newbies who need a "Go" button even next to the URL field). Now, usually pressing enter in a text field should submit the form. When you press enter in this field, it actually sets off two actions: the browser prepares the form submit, and the JavaScript creates the URL and will set document.location. In this race, if the form submit wins, friends search doesn't work, if the JavaScript wins it does. In Opera, the form submit wins..
NRG is a big news site in Israel, and presents us with another interesting timing issue. Registered users have access to a "bookmark this article" feature that will add the article you're reading to your on-site bookmarks. In Opera, saving articles doesn't work even though you get a popup window with a message stating that article was successfully saved..
Here's how the script is meant to work:
- script sets innerHTML of a SPAN to create an IFRAME that will load the address that does the actual work of adding the page to your "favourites".
- it opens a popup (loading a separate address) to tell you that the page was successfully added (I presume - I don't read Hebrew but that's what the bug report says..)
- it sets SPAN's innerHTML again, and this time to an empty string.
So we get into a race/timing condition: if innerHTML is reset to nothing too soon, the request to the address that actually adds the page to favourites won't happen. Seems Opera's window.open is faster than the competition's?
..quite un-scientifically timed, adding two recordings of new Date().getTime() after the first and before the second .innerHTML set:
Opera: 125ms
IE: 1594ms
Right. I get this image of a webmaster in blue uniform with a police baton:
"Excuse me Sir, I believe your User Agent was caught speeding over there"
"Uh, was it?"
"Yes, it opened a popup window 12 times faster than the competition.
The fine is broken functionality in the article bookmarking feature."
My first JavaScript speeding ticket..
By Niddhogg, # 17. November 2006, 21:27:36
Can something like that be fixed by an end-user (like, somehow telling Opera to slow down for certain sites) or only by the site's developers?
Thanks
By Tombaz, # 18. November 2006, 11:03:32
By scipio, # 18. November 2006, 11:31:01
By hallvors, # 29. January 2007, 13:22:26