views:

658

answers:

3

I noticed that in Firefox I can add a #MyAnchor tag to the action attribute like...

<form action="#MyAnchor">
   <input type="text" name="a" />
   <input type="text" name="b" />
   <input type="submit" />
</form>

and when the form is submitted, the anchor automatically shows up in the URL like

mypage.aspx?a=1&b=2#MyAnchor

However, this doesn't work on IE. Is there anyway I can find a happy medium for both browsers?

+1  A: 

Just a guess, but have you tried using the page + the anchor name.

<form action="mypage.aspx#MyAnchor">
bendewey
tried it but it didn't work
Robert
What version of IE are you testing this on?
bendewey
Are you performing any actions in javascript, or on postback?
bendewey
IE version 6. No actions.
Robert
A: 

You can deal with this either on the client side or on the server side:

On the server side: add a hidden element with the anchor as the value and do a redirect on an URL build on the server.

On the client side: jQuery for instance allows you to serialize a form's parameters into a URL; you would just need to append the anchor and assign this to window.location.

Maurice Perry
A: 

I've been used this to retain the fragment across postbacks:

    var f = document.forms[0];
    var index = f.action.indexOf("#");
    if(index>0)
        f.action = f.action.substr(0,index) + "#" + tabId;
    else
        f.action += "#" + tabId;
Cristian Libardo
Unfortunately, that still doesn't work for IE
Robert
Have you tried linking the page in the form action?
Cristian Libardo