简体   繁体   中英

header('Location: <anchor>') in PHP does not always work in IE11

I cannot figure out why sometimes IE11 does not go to anchor after header location is done.

I have this in PHP:

header('Location: ' . $_SERVER['PHP_SELF'] . '#order-a');

In HTML I tried both a name= and id= , neather one is working properly in IE with header('Location: .

The problem is: after header('Location: ' is done it should reload and scroll to the anchor. This is working in FF, Chrome and even in IE11 but my problem is that in IE11 it sometimes does not scroll to the anchor. (approximately in one of five cases).

Any ideas?

(Posted on behalf of the OP.)

Thanks to the questions in the comments that pointed me to the right direction I was exploring the issue more and did an example: input submitted -> header('Location: <with anchor>') and it was working even in IE. So I assumed that the problem is not actually in header('Location: ' . $_SERVER['PHP_SELF'] . '#order-a'); and IE because that is valid.

Therefore I went through my website code again and realized that the <a name="order-a"></a> is inside div that has style display: none and this div switches (thanks to JavaScript) to style display block after #order-a is contained in URL.

So when I submitted, PHP says go to #order-a but by that time #order-a has display none so it won't move to the anchor but add #order-a to the URL - thanks to it JavaScript does its job and set a div that contains #order-a to display block.

After I realized that, I just added to my JS a code that goes to the anchor after its div has display block. And it's working, thank you all for pointing me to the right direction with your questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM