[WB21] - How to use Javascript

Startbeitrag von JP am 07.07.2016 07: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

Antworten:

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

von KenKnight - am 07.07.2016 12:14
Ken,

OK, how would I scroll the whole browser to the top, the entire homepage so to speak?

von JP - am 07.07.2016 12:46
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

von KenKnight - am 08.07.2016 14:33
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!

von JP - am 09.07.2016 10:10
Way to go JP! Glad to hear you got it working.

Regards,
Ken

von KenKnight - am 09.07.2016 15:31
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.