0

Does anyone know if there is a way to use the "scroll to text fragment" feature in a link (e.g. "http://url.com/page/#:~:text=highlight%20this") in addition to another hash action in the same link? I have a page with tabs (its a divi tabs module in wordpress) and when clicking link on another page coming to this page I would like to open a tab (can be done with "http://url.com/page/#tab|2") and also highlight text within that tab. Does anyone know how to do this?

If I first go to "http://url.com/page/#tab|2" (opens the tab) then append "#:~:text=highlight%20this" or "&:~:text=highlight%20this" to the end of the url, it achieves the desired affect. But it does not when going directly to "http://url.com/page/#tab|2#:~:text=highlight%20this" (it just redirects back to "http://url.com/page/#tab|2")

Any ideas would be appreciated.

caleb1
  • 11
  • 3
  • I'm quite sure that you will have issues depending on the browser, if you even manage to make it work. As noted [here](https://stackoverflow.com/a/10851032/145939) a `/hey#foo#bar` url will be read by window.location.hash the same as if you entered `/hey#foo%23bar`. – Ant May 31 '21 at 18:47
  • @Ant That makes sense. Would it have a better chance of working if I use `&` instead of the second hash? For example `http://url.com/page/#tab|2&:~:text=highlight%20this` ? – caleb1 Jun 01 '21 at 14:59
  • Also noticed I could also use a `/` between the two hashes like this `http://url.com/page/#tab|2/#:~:text=highlight%20this` if that works any better. But as with the other solutions it only works when I go to the page with the first hash only then add the `/#:~:text=highlight%20this` to the url when on that page, it doesnt work when I go directly to `http://url.com/page/#tab|2/#:~:text=highlight%20this` – caleb1 Jun 01 '21 at 15:05
  • It all depends on how you want to parse it. `&` is a url safe character so you can parse for it safely. In general if you can result to using get request parameters, like `? = &` then do that. – Ant Jun 01 '21 at 17:17

0 Answers0