Can I add an anchor to a FORM / get message?

I noticed that in Firefox I can add the #MyAnchor tag to the action attribute, for example ...

<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 is automatically displayed in the url for example

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

However, this does not work on IE. Anyway, can I find a happy medium for both browsers?

+4
source share
3 answers

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

 <form action="mypage.aspx#MyAnchor"> 
+3
source

You can handle this either on the client side or on the server side:

Server-side: add a hidden element with an anchor as the value and redirect to the assembly of URLs on the server.

On the client side: for example, jQuery allows you to serialize form parameters to a URL; you just need to add the anchor and assign it to the .location window.

+1
source

I used this to save the fragment via 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; 
+1
source

All Articles