Question

I'm working on Drupal 8.9.6.

I'm trying to redirect users to a particular page after they add a node. I can do that without any problem, by adding the following information in the form's URL:

/node/add/author/edit?destination=/author-list

However, when I try to have a specific tab of the destination page opened, as follows:

/node/add/author/edit?destination=/author-list#tab2

It directly redirects me to /author-list, ignoring the #tab2 part. While if I enter in the browser /author-list#tab2 I get the /author-list page with the #tab2 active without problem.

Does anyone know what could be happening?

Thank you!

Was it helpful?

Solution

Most if not all browsers strip the hash (fragment) and this information is lost so you can't rely on hash being in the URL.

RFC 3986 states:

the fragment identifier is not used in the scheme-specific processing of a URI; instead, the fragment identifier is separated from the rest of the URI prior to a dereference, and thus the identifying information within the fragment itself is dereferenced solely by the user agent, regardless of the URI scheme. Although this separate handling is often perceived to be a loss of information, particularly for accurate redirection of references as resources move over time, it also serves to prevent information providers from denying reference authors the right to refer to information within a resource selectively.

Possible workaround: Create a hidden input field url_fragment and make sure it passes as a URL parameter (&url_fragment=hashvalue). Have some javascript execute on load of this page and if it finds the url_fragment in the URL make it do a scrollTop and opening of the specific tab.

Here is a question and answer that does the scrollTop if the urlParemeter EXISTS. You need to modify this script to get the actual value and also click the Tab.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top