Problems with anchors in browsers


It turns out that I'm creating a WordPress template and I'm having trouble redirecting to specific parts of the area, like the homepage. I want to go to this page , which obviously by the anchor I'm telling you to send me to that area of the page but I do not know why in some browsers like Firefox it does not work correctly and it does not send me to the anchor that it should. Is there any way to optimize it?

asked by Luis Morales Ponce 23.03.2017 в 19:18

1 answer


From what I see of your example, I think it's because the content is not loaded or not in its entirety, what you should do is wait for the page to load and then scroll.

in Jquery It would be something like this.

    if (window.location.hash) {
        $(document).scrollTop( $(window.location.hash).offset().top);

If you load the content using Ajax, then you have to scroll after the ajax was successful and paint the content. Or you can put a settimeout of a few seconds but depending on the user's connection it may fail.

EDIT: I edit to verify if you have hash and if you have the redirect, depending on whether or not you accept more parameters, you have to handle it with regular expressions

answered by 23.03.2017 / 19:36