Reading the #fragment part of the URL

Is there a way I can read the fragment portion of the url (ie

I can’t seem to find it in the request() or page() objects. I’d expect to find it in request::path, but I don’t see it there either.

Should be url::hash().

url::hash() doesn’t seem to work. I tested on locally on Laravel Valet and on my Nginx server. To be honest I have never used hash on the server, always on the client with Javascript. That’s why I was curious to give it a try.

@mrunkel you didn’t tell what you want to do, but maybe Kirby params can help you instead of hash.

url::hash('') returns “fragment”, but doesn’t seem to work without actually passing the url.

I bit of research I did after my reply tells that the hash is never sent from the browser to the server. Inspecting the request data on Chrome network tab confirms that.

If the hash is really needed on the server it needs to be retrieved with Javascript and sent via Ajax.

Makes perfect sense.

Yes, this is what I was beginning to suspect as well. I’m replicating existing (bad) behavior in a new kirby website. I’ll see if I can’t adapt the behavior. params would make much more sense, but if they are being linked from outside our control, I probably need to support existing behavior.

jQuery it is! :slight_smile:

Thanks all.

Just putting this out there, but couldn’t you fix it by using params and use .htaccess or kirbys router to translate old bad links into the new good links? Seems a shame to go to all the bother of updating the site, and stick with a legacy thing.

I think that’s six of one, half dozen of the other. I like to keep all my stupidity in one place if I’m forced to be stupid. :slight_smile:

If the hash is not sent to the server, you can’t intercept and reroute it server side.

Oops… Of course.