How to Read / Write or Preserve Fragment Identifiers on Post-back

╄→гoц情女王★ 提交于 2019-12-25 01:45:52

问题


I'm using fragment identifiers to run a tabbed browsing control and it would be nice if the post-back could preserve the tab as that is less jarring to the user. To that end I've been searching for a method to preserve the fragment identifier and am at a total loss.

Is there a way to read or save the fragment identifier from the referring url during a page post-back in ASP.NET?


回答1:


You can't save/retrieve URL fragments on the server side because Browsers don't send them -and they aren't supposed to- to the server. See here.

Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application (see below) fragments do not participate in HTTP redirections.




回答2:


You can use document.location.hash from javascript to read the fragment. You can use this to send something to the server in the POST, and then the server could include it in a 30x redirect.



来源:https://stackoverflow.com/questions/7391903/how-to-read-write-or-preserve-fragment-identifiers-on-post-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!