重定向子域 (IE) 时保留锚点
火狐浏览器:
http://example.com/about/#anchor -> http://www.example.com/about/#anchor
Internet Explorer 6-8 :
http://example.com/about/#anchor -> http://www.example.com/about/
为什么 IE 中的锚点会被丢弃?我能做些什么吗? (查询字符串不会被删除,只有 #xyz 部分)
PHP 标头或 javascript 重定向是我唯一的选择吗?感谢所有提示。
更新:似乎哈希未发送到服务器。将 PHP 301 标头和 javascript 重定向(带有 location.hash)结合起来会是一个好的解决方案吗?
Firefox:
http://example.com/about/#anchor -> http://www.example.com/about/#anchor
Internet Explorer 6-8:
http://example.com/about/#anchor -> http://www.example.com/about/
Why is the anchor dropped in IE and what can I do about it? (Query string is not dropped, only the #xyz part)
Is a PHP header or javascript redirect my only option? Thanks for all hints.
Update: Seems as the hash is not sent to the server. Would combining a PHP 301 header and a javascript redirect (with the location.hash) be a good solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
锚点永远不会发送到服务器,因此任何服务器端解决方案都无法保留它们。
Anchors are never sent to the server, so no server-side solution can retain them.
在Tomcat/JSP中也有类似的问题,不知道PHP。在 Tomcat 中,规则是 #anchor 仅适用于浏览器/用户代理,因此您无法获取它。我的解决方法是在页面中使用 Javascript 来实现重定向。我的建议是,如果你不能很快让它在 PHP 中工作,那么开始尝试 Javascript 解决方法。
Had a similar problem in Tomcat/JSP, don't know about PHP. In Tomcat the rule was that the #anchor is only intended for the browser/user agent so you can't get it. My workaround was to use Javascript in the page instead to achieve the redirect. My tip would be that if you can't get it working in PHP soon then start trying a Javascript workaround.
在服务器端重定向期间只能使用服务器端锚点。它们必须有一个 ID(尽管我不确定它们是否必须以编程方式创建)
或者您可以传递一个参数并使用 onload 将焦点移动到 ID 或超链接。
Only server side anchors can be used durring a server side redirect. They must have an ID (although I am not sure if they have to be created programatically)
Alternately you can pass a parameter and use the onload to move the focus to the ID or hyperlink.