PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WB21] - How to use Javascript
[WB21] - How to use Javascript
Iniciado por guest, 07,jul. 2016 09:38 - 5 respuestas
Publicado el 07,julio 2016 - 09:38
Hi All

WB21 - Classic site

I have an iFrame in which a long page is displayed on user request. If the user scrolls the browser down and then requests the same page but for a different item then it displays as at the browser scroll point. I would like the page to start at the top however.

Fabrice suggested using PagePosition() but I cannot get this to work and have tried putting it in to various code sections with no effect.

I have then found a Javascript code which can reset the browser scroll as follows:

window.scrollTo(x-coord, y-coord);

Can someone explain to me how I can call this very simple bit of code from WebDev?

TIA
Publicado el 07,julio 2016 - 14:14
Hi JP,

I think the simplest way to use that code is inside some browser code event, you could use it like the following:

EXTERN window window.scrollTo(0);
The extern statement is telling the IDE that the window object will exist at runtime, so don't try to evaluate it during design time. I use the EXTERN document function quite a bit.

However, I don't think that is actually going to have the effect you are expecting on the iframe window. I think you will probably need to manipulate the iframe contents itself with something like:

EXTERN document scrollTop = document.getElementById(IFRAME_ID).contentWindow.document.body.scrollTop(0);
I think the big issue is going to be hooking to click events on the iframe. If you have control of the code in the iframe, then you can certainly place your scrollTop code directly in that code to fix the issue.


Regards,
Ken
Publicado el 07,julio 2016 - 14:46
Ken,

OK, how would I scroll the whole browser to the top, the entire homepage so to speak?
Publicado el 08,julio 2016 - 16:33
Hi JP,

if you have WB21, check out the responsive example. In the click event of the menus at the top right you'll see a method in use to scroll the page.

Cheers!
ken
Publicado el 09,julio 2016 - 12:10
Ken,

Thank you. I have found the sample and studied it - is has shown me how to add the JavaScript code and I have it working. Thanks!
Publicado el 09,julio 2016 - 17:31
Way to go JP! Glad to hear you got it working.

Regards,
Ken