Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,503,073
Community Members
 
Community Events
180
Community Groups

User macro to periodically reload page shows unexpected behavior (reloads edit page too)

Edited

Hello everyone, 

We had the request from a group of users to have a dashboard-type page reload periodically, so that they can see changed content. 

Based on a really old post here (https://community.atlassian.com/t5/Confluence-questions/Page-auto-refresh/qaq-p/306485), I have come up with a simple user macro that puts in a piece of javascript that essentially hooks up a setTimeout() function to the window.onload event, which in turn calls a page reload (code: see below).

The macro has the desired effect, but when you enter page edit mode, it triggers the reload once more while already in edit mode. This is not desirable, and I am unclear as to why this happens - my understanding is that the window.onload() functions would not be executed as soon as the edit page is loaded, as the macro is not active there.

I am admittedly not an expert in the inner workings of Confluence, can anyone point me into the right direction as to how I can fix the behavior to only cause reloads when the page is in viewmode?  

 

Many thanks in advance, 

Michael

 

User macro: 

## Based on the discussion in https://community.atlassian.com/t5/Confluence-questions/Page-auto-refresh/qaq-p/306485
## Auto Refresh Wiki Page
## @param interval:title=Intervall|type=string|required=true|default=60|desc=Interval in seconds between triggered page reloads. Don't set this too small, otherwise you will put load on the server.

<script language="javascript">
// Assign an anonymous function to the onload event
window.onload = function(){
// The time out value is set to be $paraminterval seconds
setTimeout(' document.location=document.location' , $paraminterval * 1000);
}
</script>

 

 

 

1 answer

1 accepted

0 votes
Answer accepted

The below script example hooks into the events that are fired when entering into edit mode. So you would need to change your code a bit to turn off the reload when these events fire off.

AJS.toInit(function () {
    //Launch if edit button clicked
    AJS.bind('init.rte', function (a, e) {
        AJS.$(e.editor.getWin().parent.document).bind("mode-changed", function () {
            // code to turn off page reload goes here
        });
        AJS.$(e.editor.getWin().parent.document).bind("iframeAppended", function () {
            // code to turn off page reload goes here
        });
    });
});

Hi Davin, 

Thanks a bunch - this was the help I needed.

One remark: I was't able to get it to de-register (using clearTimeout()) the refresh when the code was within the nested bind() calls - but putting the code directly into the function that is bound to the 'init-rte' event worked. 

 

Many thanks, 

Michael 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events