开发者

Why does <button> make "GET" in Firefox/Chrome, but "POST" in Opera?

I'm developing a website (ASP.NET Webform with C#) where I have a <button> element.

Here's the code snippet:

<a href="ThisPage.aspx" ID="myButtonID" runat="server">
    <button>Configure new trip</button>
</a>

When I use Firefox or Chrome, this code does a "GET" ov开发者_如何学Goer this ThisPage.aspx. That's what I want to do, actually.

The question is that the same code does "POST" when I use Opera. Does anyone know what shall I do to make this button act the same way using Opera?


Probably because FF/Chrome handles the click on the <a /> tag and Opera does it on the <button /> tag.

What you are looking for (I guess) is having a <a /> tag renderes as a button? In that case have a look at this for at good tutortial on how to style an <a /> tag like a button

What you are doing is to some extent similar to adding a textbox to an anchor tag, i.e. sematically wrong.


I'm guessing it's within a form tag?

If so, try setting the method of the form to "get".


If you're not doing any AJAX operations, and clicking on the button is expected to navigate to 'ThisPage.aspx', then I'd consider styling the <a> element - as suggested by @veggerby - and removing the <button> </button> elements.

However, this could be confusing for the user, who might not expect a button within a form to be a navigational element. I'd tend to keep the form and its controls visually separate from other elements on the page - using a <fieldset>, maybe.


How do Firefox/Chrome submit the "GET"? Are there any parameters? If you want to link to ThisPage.aspx then just do it without a button.

A form can be GET or POST, but not both. So if the button is inside a form it will always submit the data from the form, and should use whatever method is set on the form.

Perhaps you can post the actual HTML output to the browser, rather than the ASP code? I have a feeling you may be generating a form-within-a-form. In which case the solution would be to keep the forms separate if possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜