Is it possible to add an anchor to a FORM post/get?

后端 未结 3 1126
北荒
北荒 2021-01-19 18:08

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

相关标签:
3条回答
  • 2021-01-19 18:11

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

    <form action="mypage.aspx#MyAnchor">
    
    0 讨论(0)
  • 2021-01-19 18:16

    I've 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;
    
    0 讨论(0)
  • 2021-01-19 18:29

    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.

    0 讨论(0)
提交回复
热议问题