I see.... so the issue here is that the "return to previous page" option won't remember the anchor you were on in the previous page because the value is saved on the server and the anchor is a client html reference that is never accessible to the php.
The only potential work around would be to create a client side javascript to pass the value of the anchor to the php using AJAX and store it that way. I could help with that in a premier support ticket, but otherwise you will have to find a way to link to the page where the anchor in the link isn't necessary.
Anchors will work if you set them in the Success URL in the actual login server behavior. Maybe you could turn off the "return to previous page" option and use a successful login link to return to an appropriate starting page, which could have an anchor element.