使用锚标记和 IE7 进行标头位置重定向
嘿! 这是我的问题,它可能只是浏览器问题,但任何帮助/想法都会很棒!
几乎我有以下重定向:
header("Location: page.php#images");
在大多数现代浏览器中,它会毫无问题地重定向到 page.php#images,但在 IE 中,它似乎会删除 #images。 有人遇到过这个吗? 到目前为止,我唯一的选择(我认为这是一个糟糕的选择)是通过 JavaScript 重定向。
谢谢!
更新
我发送了一个简单的沙箱,无论有没有绝对 URL,它似乎都可以正常工作。 我想我的实际应用程序中发生的其他事情与它相冲突。 等我弄清楚了,我会更新的,谢谢大家的回复!
更新2
我发现了问题所在,但我仍然不确定修复方法。 事实证明,是文件输入破坏了它。 您可以在此处查看它的实际效果 http://www.stiprojects.com/anchor/ 它有效在 Firefox 中很好,但在 IE 中就崩溃了。 重定向中的源代码是:
header("Location: http://www.stiprojects.com/anchor/index.php?one=1&two=2#/images");
你看到了什么我没有看到的东西吗? 我很困惑!
Hey there! Here is my issue, it could just be a browser issue but any help/ideas would be awesome!
Pretty much I have the following redirect:
header("Location: page.php#images");
In most modern browsers it will redirect to page.php#images without any problems but in IE it seems to strip the #images. Has anyone come across this? So far my only option (which I think is a terrible option) is to redirect through JavaScript.
thanks!
UPDATE
I sent up a simple sandbox and it seems to work fine with or without an absolute URL. I guess there is something else going on in my actual app that is conflicting with it. I'll update when I figure it out, thanks for all the responses!
UPDATE 2
I found out what the problem is but I am still unsure on the fix. It turns out that it was a file input that was breaking it. You can see it in action here http://www.stiprojects.com/anchor/ it works fine in firefox but breaks in IE. the source code in the redirect is:
header("Location: http://www.stiprojects.com/anchor/index.php?one=1&two=2#/images");
Do you see anything that I'm not seeing? I'm so confused!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Location
标头需要每个 HTTP 规范。 尝试使用绝对路径。 勘误表指出文档片段 (#id) 允许在Location 标头,但是当用户链接到带有片段的页面时的行为(例如http://example.org/a_redirector#this
其中a_redirector
重定向到 <代码>http://example.com/destination#that)未定义。The
Location
header requires an absolute path per the HTTP specification. Try using an absolute path. The errata says that document fragments (#id) are allowed in the Location header, but the behaviour when a user is linked to a page with a fragment (e.g.http://example.org/a_redirector#this
wherea_redirector
redirects tohttp://example.com/destination#that
) is undefined.是的,确实如此。 如果使用绝对路径可以防止这种情况:
Yes that is true. It can be prevented if you use an absolute path: