-2

I am using this setTimeout("document.location.reload();", 10000); to refresh the page every 10 seconds. And after reloading fully, it gets back to the original location. But for like 0.1 second, the top of the page is shown. You can see this in the video:

https://drive.google.com/file/d/1LKDyqhFnKRapUY_fEugIS5Te-2tawlmk/view?usp=sharing

rahul sharma
  • 109
  • 1
  • 8
  • 1
    Passing setTimeout a string of code for it to execute is usually ill-advised. It’s hard to read (and thus hard to maintain and/or debug). It uses an implied eval(), which is a potential security risk. It’s slower than the alternatives, as it has to invoke the JS interpreter. – Krzysztof Krzeszewski Feb 28 '20 at 13:42
  • Why is it necessary to __reload__ the page? – Cerbrus Feb 28 '20 at 13:43
  • 1
    Consider a different architecture where you use ajax to reload just the parts of the page that have the changed information. – Heretic Monkey Feb 28 '20 at 13:44
  • The images sometimes change. So i want to check every 10 second, if the image change and display the new one. – rahul sharma Feb 28 '20 at 14:06
  • Yea, you should be querying the server for just the images instead of reloading the whole page. – Cerbrus Feb 28 '20 at 14:08
  • Okay. I did not want to use Ajax, but I guess, I have to now. – rahul sharma Feb 28 '20 at 14:19

2 Answers2

0

As i see it, your images didn't load yet that is why it looks like it jumps up and than down. That is why your top row is visible at the very beginning. Scroll seems to stay at the bottom. Scroll isn't the problem here (as i see it).

I don't know how images are shown (are you using any data in the background to generate output). But solution to prevent top row to be seen would be in CSS. Presetting width and height of 'img' tag.

If you can see i posted two images of the issue.

There can be few ways to fix it. One way I can think of is using 'window.onload'. I guess you could show page when HTML is fully loaded with all images to stop 'jumping' after each load. It could help.

Maybe this post will help: window.onload vs document.onload

Let me know if this was helpful for you finding solution for a problem.

  • The OP wants to reload the page to refresh / replace some of their images, but doesn't want the DOM rebuild associated with the reload. "Using" `window.onload` doesn't magically fix his problem... – Cerbrus Feb 28 '20 at 14:16
  • The 1st image in your picture is a "SVG" (showing 6 wind turbine) and in the second image, both of them are images. – rahul sharma Feb 28 '20 at 14:17
  • I guess, Ajax is my last option? – rahul sharma Feb 28 '20 at 14:19
  • I assumed in between 'Image of ..' and under 'Graphics' images are loaded. The best solution in your case in my opinion is Ajax. – user3649898 Feb 28 '20 at 18:00
-1

Detect event refresh in javascript, save the value of x-scroll in a cookie, if cookie exist when reload, put the value of x-scroll to this value

Felipe Mora
  • 42
  • 1
  • 11