Can't jump to Anchor in Expand macro
Asked by Mick Davidson:

I've got a page with several Expand macros on it.

Below these on the page (and not within the Expand macro) are sets of data that contain links to headings within the Expand macro. The headings have the Anchor macro.

If you click on the link that goes to one of the headings within the Expand macro, and it is NOT already expanded, then the link doesn't work.

If you expand the area you want to jump to first, then click on the link, you jump to the appropriate heading.

I hope that makes sense. :smile:

Is this expected behaviour or a bug?

I'm running Confluence Server, 5.4.1.

Cheers.


Answers:
author: Stephen Deutsch
body: This is a known issue:

<https://jira.atlassian.com/browse/CONF-27357>

However, if you look in the comments of the ticket, I wrote a workaround where you can add some Javascript to your Confluence instance that will enable this. If you copy everything except the first line into your custom HTML, then it should work on all your pages.

comments: author: Mick Davidson
body: Stephen, that's great, thank you.


author: Brandon Roesler
body: This work-around used to work great for me, but now that my company has upgraded to 6.0.7, none of my links work any longer. Any suggestions?


author: Stephen Deutsch
body: strange, I tested it on Confluence Cloud, which should be the latest version, and it worked OK... Might something else have changed during the upgrade?


author: Jeff Robertz
body: Guys, I a newbie to such things. Where do you need to copy the macro in Confluence cloud?


author: Stephen Deutsch
body: Hi Jeff,

unfortunately it will currently not work for all users in Confluence Cloud, as there are restrictions as to what you can do especially when it comes to custom HTML/Javascript. You could install a browser extension such as Greasemonkey/Tampermonkey and package it as a user script, but it would only work for those users with the user script and browser plugin activated.


author: Scott Fordin
body: Thanks so much, Stephen. Your code works beautifully! I have one minor niggle though for which I haven't been able to figure out a workaround...

To make your expand trick work for a given targeted text block in an Expand macro, the Anchor macro for that targeted text must be embedded within (not before) the Expand macro in which the text block is contained. So far, so good, yes?

However, because the Anchor macro is embedded in the Expand macro, when a user follows a link to the targeted page, the page is opened and the viewport is scrolled to the expanded content, just past the Expand macro's title string. So, the user sees the expanded content, but does not see the title string for that content, which can be disorienting.

I've been trying to find a way, using JavaScript and/or JQuery, to scroll the viewport up just one line after the page is loaded and the expanded text is opened. Any recommendations? I know it's a no-no in most cases to grab control of the input focus. All I want to do is shift the viewport up by one line. Alternatively, I suppose I could add a redundant or similar title string in the Expand text block, but that's icky from a doc standpoint.

Thanks again!


author: Tim Bisaerts
body: The solution works great!

Did someone by accident find a solution for the ui-expand function (part of the **[RefinedToolkit](https://marketplace.atlassian.com/apps/1211136/refined-toolkit-for-confluence?hosting=server&tab=overview)**plugin)


author: ????????? ???????
body: Hi, guys!

So basically this workaround can be applied only if you administrator. Otherwise you cannot do anything, and the issue is not going to be fixed.

Am I right?

Regards,

Kate

comments: author: Mario Siebeck
body: No


Tags: anchor

bug

expand

macro