onClick function works in Preview, not in Saved copy

I added an anchor to a page (top of page) and the following HTML (raw) to a point further down the page:

<input type="button" onClick="window.location.href='#top'" value="Top of Page" />

When I 'preview' the page, clicking on the button takes me to the top of the page, as expected. After I 'save' the page, the button does not work. Is there something in the actual page that is blocking the Javascript action? How can I unlock this feature?

1 answer

It should work, you just need to reload the page after saving.

I tested it successfully with the following code:

{html}
&lt;h1 id="top"&gt;Test&lt;/h1&gt;
{html}

{loremipsum:50}

{html}
&lt;input type="button" onClick="window.location.href='#top'" value="Top of Page" /&gt;
{html}

Hope this helps

Adding the 'id' to a DOM element near the top was the missing piece. Thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,108 views 17 14
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you