Go to home page mail me! RSS Feed
FoxMetrics Web Analytics

Button element in IE vs FireFox behave differently

Thursday, June 05, 2008 10:52 PM

When are all the browsers going to unite? It's hard enough to build solid web applications within reasonable time. For as long as I've been building web applications, it would be a dare to say that every application that I build work in at least the top 3 major browsers, and that's because I learn something new everyday and it just doesn't happen that way.

Today while working on a new project for one of my clients, I was being all fancy by using the "Button" element which I don't normally do. Instead of using "<button>", I usually use "<input type=button". however, today I was going out of habit and to my surprise the "<button>" control does not work the same way across browsers.

Example, if you create a simple button control on a basic html form an perform a simple task on the onclick event such as a redirect, you will find out really quickly that it works perfectly fine in IE but not in FF.

<button onclick="window.location.href='somepage.html';">New Page</button>

It turns out that in FF, the default action for the button control is to submit a form, so you have to return false to use the button control for anything else other than submitting a form.

<button onclick="window.location.href='somepage.html';return false;">New Page</button>
weird huh?

Your Comments.

  • # re: Button element in IE vs FireFox behave differently

    GravatarThat's because Firefox is follow the W3C recommendation, that clearly state the default action of a button is as submit button. http://www.w3.org/TR/html401/interact/forms.html#h-17.5
    IE's default behavior is the none standard one.

    Left by Mike at 7/11/2008 5:12 PM

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 3 and 3 and type the answer here:

Preview Your Comment.

 
Next entries »