Search code examples
iframescrollblazor-server-siderazor-pages

In my Blazor server side app's razor page i have an iframe that should scroll to page end when razor page is loaded. How can I do that?


In my Blazor server side app's razor page i have an iframe that is linked to a .txt log file. As the log file is very large, I want that the iframe should scroll to page end automatically when razor page is loaded. How can I do that?

(The latest alarm is added to the end of the page and I do not want to modify the log file)

in my simplified razor page I have tried following but didn't work.

<body>
  <iframe src="/main_log.txt" width="1500" height="800" frameborder="0" onload="scrollTo(1,99999)"></iframe>   
</body>

Solution

  • The `onLoad’ event needs to talk to the iframe. It would be something like.

     document
       .getElementsByTagName('iframe')[0]
       .contentWindow
       .scrollTo({top: 999999, behavior: 'smooth'})