Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I prevent html macro javascript running when switching into edit mode?

Helen Setchell August 16, 2018

I've written some javascript that does a bunch of asynchronous API calls to display third-party content on the current page.

(I also do this as a way of displaying confluence content instead of using the content macros, because too many content macros on one pages slows the page load enough for users to start complaining; asynchronous loads provide a better user experience.)

This works fine, except that if I click the 'Edit' button, I have to wait while all the javascript re-runs (i.e. creates the view mode again*) before the page even tries to switch to edit mode.

*I presume this always happens when switching any page into edit mode, but we don't normally notice it?

Is there any way to stop the javascript running on this pre-edit page view load? Something wrapped around my code that says "if edit button has been clicked, abort"?

(I don't have access to create plug-ins etc btw - only front-end javascript)

PS - we have collaborative editing enabled

1 answer

1 vote
Gonchik Tsymzhitov
Community Champion
March 23, 2020

Looks from there event checker will help

https://developer.atlassian.com/cloud/confluence/jsapi/confluence/

e.g. it helps to me

Helen Setchell March 26, 2020

Thanks for this link (I'm using Confluence server btw).

I wasn't sure how I would have implemented this for my scenario:

I have a page in Confluence containing an HTML macro. In that page I can either write some javascript or link to an javascript file attached to the page. My js is doing ajax calls.

  • When I view the page I see the results of my script.
  • If I click Edit, the script runs again before showing me the edit screen.

Update: as far as I can see this is no longer an issue.

Which might be since the upgrade to Confluence 7.3.1 (or an earlier version and I didn't realise this had resolved itsself as I have added buttons to 'run javascript' to most of my stuff now).

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events