On some larger pages where scrolling is inevitable, it might be required to stay at the same position in the window after an submit event. With that the user won't loose focus of the current context.

Scenario: Imagine a long page divided into two areas. An information region at the top and a region for user-interaction below. The information area alone doesn't fit on the screen and the user has to work with the area below. Multiple submits are required by the user to complete his task. The problem now is that after every submit and page-reload the window position gets reset. The user needs to scroll down again and again.

The requirement therfore is to somehow keep the window position, even after submit and page-reload. This is easily done in three simple steps, explained below.

1. Create a hidden and  item that is required for saving the window position - lets call it P41_WINDOW_OFFSET_TOP.

2. Create the first Dynamic Action for saving the window position.

The required True-Action needs to store the window-position in P41_WINDOW_OFFSET_TOP. This can be done with a SetValue Action and a single line of JavaScript.

$(window).scrollTop();  // get the window offset from the top

3. Another Dynamic Action reads out the Value of our hidden item P41_WINDOW_OFFSET_TOP at PageLoad and scrolls the window to the according position. This dynamic action has to be executed only if the item value is set.

The True-Action is of type Execute JavaScript Code and consists of following single line of code.

$(window).scrollTop(&P41_WINDOW_OFFSET_TOP.);

 

Don't forget to include the item in your submit-event. (e.g. Branch - see example below)

Feel free to also include the horizontal window offset if neccessary, which can be done in exactly the same way with $(window).scrollLeft();

You may try it out yourself going to the Live-Example.