header Location redirect with anchor tag and IE7

别等时光非礼了梦想. 提交于 2019-12-20 06:37:41

问题


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!


回答1:


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 where a_redirector redirects to http://example.com/destination#that) is undefined.




回答2:


Yes that is true. It can be prevented if you use an absolute path:

header("Location: http://www.example.com/page.php#images");


来源:https://stackoverflow.com/questions/963211/header-location-redirect-with-anchor-tag-and-ie7

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