Stoyan from Yahoo! presents some surprising facts.
As a sequel to this browser shortcuts post, here're two new shortcuts that rocked my world (ok, almost..) :
- F4: opens a select box. Seems like a standard for all UIs! (Windows/Linux at least)
- Tick (') key in FireFox: would switch to 'search' mode just like slash (/), but would search for links only. Just type the beginning of the link's name and hit Enter.
Do you know any other shocking keyboard shortcuts?
On a completely other subject, I was fighting (along with a collegue) today with Apache httpd's configuration. The web server seemed to "automatically guess" URLs in a weird fashion.
The cause is that we had the MultiViews feature enabled. With MultiViews, when a URL points to a nonexisting file, i.e. http://mydomain/my/file, apache tries to look for an existing file which looks similar to the directory (I won't describe here the exact algorithm), i.e. http://mydomain/my.php. Then it loads it instead, and the user doesn't get 404.
Maybe some people need it.. but it's also weird and error-prone..
At work we have a page that loads multiple PHP scripts (in parallel), using XMLHttpRequest.
Later, we noticed that if one PHP script responds very slowly (i.e. when we put sleep(120) inside), all the others are waiting till the first one finishes loading. In other words: the load is serial, not parallel!
A little research revealed an interesting phenomena: PHP session locks the session file till the session is closed. By default, the lock starts with session_start() call, and ends at the end of the PHP script!
Continue reading →
Apparently it's already supported by all modern browser except IE - which needs the Explorer Canvas plugin.
In the following code, I wanted the parent div to expand to the size of the child. But it doesn't work this way:
<div id="child" style="width: 500px">Child Text</div>
Instead, the parent takes 100% of the screen width and does not shrink to the width of the child. Quite a long googling revealed some interesting facts:
- div is a 'block', so it always tries to take all available width. (unlike a span which is 'inline')
- Using 'float: left' in the parent, makes it "shrink wrap" over the child, thus not trying to take all available width.
adding 'clear: both' will prevent the float from causing the other blocks to join the same line.
- If the parent is a <td>, then the "shrink wrap" effect takes place.. (Also with <div display="table-cell"> on firefox, but not in IE)
Many websites use session-cookies (PHP session installs such a cookie, for example). Session-cookies have expiry time of zero, and the browser usually deletes them after closing its window. This is very useful for a 'log-in' session, like in your bank account, gmail, etc.
So all browsers delete the cookie as you close them, but what happens when you open a new browser window or tab? Does it also respect this temporary, session cookie? If you're logged in to gmail from one window, can you open a new browser window with another gmail account?
The answer is not surprising: that depends on your browser.
Continue reading →
Today I wanted to catch a 'mouse-out' event in a div. Every time the mouse leaves the div, I want to call a function So.. there's the onmouseout event which, at first sight, does exactly what I needed.
<div id="parent" style="height: 500px; width: 500px;" onmouseout="alert('out!');">
<table id="child"><tr><td>child text</td></tr>
HOWEVER - if the div contains child elements (it usually does.. like above example), when mouse moves from the "bare naked" div directly to its child element, an 'onmouseout' event is called from the div, while the mouse is still inside the borders of the div. And the worst news is that it's not a bug! 🙂
So straight to the sad solution: onmouseleave event does exactly what I needed, but isn't standard and is IE-only (same goes for onmouseenter). As Rick summed it in the post which solved my issue today: "Bummer."
So bummer, but the good thing is that among the reads, I've found this must-read article which talks about the order browsers handle the events, and how to deal with it.
After some struggling with how the Daylight Saving Time change affected my code, I realized that one shouldn't mess with the time zone offsets on his own (i.e. Add or Subtract hours manually from the UTC time), because underlying libs already implement it - and probably better (yes, including DST changes, works flawlessly!). Here are the new simple rules I set to myself:
- Absolute time: Store dates only relative to UTC (usually [milli]seconds since Unix epoch or another reference date. The familiar Timestamps are measured as UTC and not as Local Time!
- Absolute-to-Local: When local date matters, convert UTC-to-local (and vice versa) using the already-existing methods:
Bottom line: stick to UTC as much as you can, it's good for you.
Trivia line: Morocco is GMT+0 and has no Daylight Saving Time (so it's identical to UTC). Good for them, eh?