How to Read / Write or Preserve Fragment Identifie

2019-08-30 19:25发布

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?

2条回答
不美不萌又怎样
2楼-- · 2019-08-30 19:47

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-08-30 19:52

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.

查看更多
登录 后发表回答