Archive for the ‘IE’ Category

location.replace and Back button bug in IE

April 12, 2007

In our web application, after the user logs on, we display a “Please wait…” screen and then the user is taken to the main screen, using a “location.replace(URL)” function call.

Yesterday, due to another problem, we noticed that when the user clicks the Back button on Internet Explorer (6 & 7), he is taken to the “Please wait” screen, and then back to the main window, instead of being taken to the login screen, since the “location.replace()” method promises according to all the documentation we found not to put the current page in the browser history object, so pressing the browser Back button should take you to the previous page.

Both my colleague and I put up a clean sample HTML files to test it, but where in my test page the problem didn’t re-occur, it did with my colleague HTML files. A little search for differences showed that I wrote a simple HTML page from scratch:

<html>
  <body>
    <form>
      <input type=button value=click onclick=”location.replace(‘b.htm’)”>
    </form>
  </body>
</html>

But my colleague used a template to create her HTML file, so her files looked like:

<html>
  <head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
    <title>EXAMPLE</title>
  </head>
  <body>
    <form>
      <input type=button value=click onclick=”location.replace(‘b.htm’)”>
    </form>
  </body>
</html>

Checking it further, we found out that when you use location.replace (and also window.open with the last parameter set to true) and the page you switch to has a Content-Type http-equiv <meta> tag that has a charset setting in its content attribute, Internet Explorer for some reason adds the current page to the history object, so pressing the Back button will take you to that page.

Note that for the bug to happen the new page to which you replace need to have this <meta> tag, and the current page content has no affect. Also, you must set the charset in that page – setting a content type without a charset (e.g. “text/html;”) doesn’t cause the problem. Finally, setting the content type using a real HTTP response header and not using an http-equiv <meta> tag also doesn’t cause the problem.

The fix was simple as the page we were opening was actually a frameset, so the charset setting in it could be safely removed.

This is indeed an interesting bug, to which I found no reference on the web.

Advertisements

IE bug with a label related to select

September 6, 2005

Here is a nice IE bug I just found.
When a <label> is attached to a <select> element, and the user clicks the label, the <select> is selected (which is nice), but its selectedIndex becomes 0 (that’s not so nice).

Here is an example page.

Update: I found out that this is an MSDN report bug. See http://support.microsoft.com/default.aspx?scid=kb;en-us;314279&Product=iep. They also suggest a workaround – use the onfocusin event to store the current selection before the focus is actually moved to the list, and reset it later. However, they say “you can only work around this problem in Internet Explorer 6” – I’m not sure why, as the onfocusin event is said to be supported on Internet Explorer 5.5 and later.

However, I would suggest a much simpler solution – simply handling the label event ourselves, without IE to interrupt and destroy. In their sample, I would use:
<LABEL for=”test” onclick=”document.getElementById(this.htmlFor).focus(); return false;”>Citizenship Status:</LABEL>

In my tests, it does the job perfectly well.

Open This URL

January 22, 2005

I finally sat down to find a solution to a problem that been bothering me for a while now. Sometimes I see a URL in a web site (this mostly happens in forums or blogs), which is not a link, so if you want to see it, you must copy and paste it.

Avant Browser version 10 came with a little toolbar that sometimes show near your selection, but this toolbar is not predictable – I couldn’t figure out when exactly Avant decides to show it, and it only has a Search button. Normally, when Google is searched for a URL, this URL is opened, but I don’t want to count on this.

So, what I did is creating a file in d:\winnt\web named OpenThisURL.html, with the following content:

<script>
external.menuArguments.open(external.menuArguments.document.selection.createRange().text);
</script>

And I also added a new registry key to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt named “Open This &URL” with default value set to d:\WINNT\Web\OpenThisURL.html. I also added a binary value named Contexts, with its value set to “10 00 00”. Now, after restarting the browser, selecting the URL text, and right-clicking adds an “Open This URL” menu item, which opens it in another window.

This even works well in Avant Browser.