B4J Question Automatic scroll top page in webapp after updating. How can I do?

By modifying Erel's Dynamic Keys example I made a websocket based webapp showing a gallery of images.
When I update the gallery the browser I would like to scroll the broser at the beginning of the gallery as it remains in the previous position,
for example half gallery. How can I do?


000.jpg


code example used:
Private MainDiv As JQueryElement
    
private Sub SetPage
    Dim sb As StringBuilder, sbRep As StringBuilder
    sb.Initialize
    
    ' RICERCA podotti
    Dim img  As String,i As Int
    Query="select * from artpro where  reparto=" & rep
    Dim cur As ResultSet
    cur = Main.SQL1.ExecQuery2(Query,  Null)
    Log("ExecuteMemoryTable: " & Query)
    
    Do While cur.NextRow
        i=1+i
        img=cur.GetString("IMMAGINE")
        sb.Append(fx("<div class=°w3-quarter°>"))
        sb.Append(fx("<img id=°img" & i & "°  src=°"  & img &  "° alt=°" &   img  & "° style=°width:100%°>" ))
        sb.Append(fx("<h4>" & cur.GetString("des")  & "</h4>"))
    Loop
    sb.Append(fx(" </div>"))
    sb.Append(fx(" </div>"))
    MainDiv.SetHtml(sb.ToString)
End Sub

code part html page:
  <!-- !PAGE CONTENT! -->
    <div class="w3-main w3-content w3-padding" style="max-width:1200px;margin-top:100px">
        <div id="maindiv">
            <!-- First Photo Grid-->

        </div>
 
Solution
(staff you can kindly put SOLVED on the therad title, I am not enabled to edit)

I solved it by simply inserting this javascript function
HTML:
    <script>
        function scrollToTop() {
            window.scrollTo(0, 0);
        }
    </script>

and calling it after updating the gallery
with the B4J functions:
server b4j:
ws.RunFunction("scrollToTop", Null)
ws.Flush
(staff you can kindly put SOLVED on the therad title, I am not enabled to edit)

I solved it by simply inserting this javascript function
HTML:
    <script>
        function scrollToTop() {
            window.scrollTo(0, 0);
        }
    </script>

and calling it after updating the gallery
with the B4J functions:
server b4j:
ws.RunFunction("scrollToTop", Null)
ws.Flush
 
Upvote 0
Solution
Top