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

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

podvinec February 27, 2019

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
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 27, 2019

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
        });
    });
});
podvinec February 28, 2019

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