Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 550847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:19:54+00:00 2026-05-13T11:19:54+00:00

I just found a snippet of code today as I need to refresh a

  • 0

I just found a snippet of code today as I need to refresh a page of mine so that a PHP script can run again to show new results from the DB every minute or so.

if (document.images)
    setTimeout('location.reload(true)',1000*60*15); // forces a reload from the server
else
    setTimeout('location.href = location.href',1000*60*15);  // just reloads the page

Whats the difference between the two? I mean do they not reload the page? How can the JS code force a reload from the server?

Thanks all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:19:54+00:00Added an answer on May 13, 2026 at 11:19 am

    The snippet will try to make a full page reload, if there are images on the page, otherwise it just make a redirect to the same page itself.

    Using location.reload(true);, the true argument causes the page to always be reloaded from the server.

    But that condition is always true, since document.images is an HTMLCollection, and it will never evaluate to false, even if there are no images on the page, the only values that evaluate to false in a boolean expression are null, undefined, 0, NaN, an empty string, and of course false.

    If you want to make that condition work, you should check the length property of document.images, the length property is numeric and that means that it will evaluate to false only when its value is 0:

    if (document.images.length) {
        setTimeout(function () {
            location.reload(true); // forces a reload from the server
        }, 1000*60*15); 
    } else {
        setTimeout(function () {
            location.href = location.href;
        }, 1000*60*15);  // just reloads the page
    }
    

    Notice also that I’m now using function expressions instead of strings as the first argument of setTimeout, if strings are used the code will be evaluated at runtime (equivalent to a eval call) and that is not really considered as a good practice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just found IPython and I can report that I'm in deep love. And
I've just found in my java project this code snippet: List<IssueType> selectedIssueTypes = new
I found this nice snippet of code online: rkApp = Registry.LocalMachine.OpenSubKey(SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run, true); Which runs
I just saw a code snippet with a piece of syntax that I have
I just found myself creating a class called InstructionBuilderFactoryMapFactory. That's 4 pattern suffixes on
I just found out that by converting PNG32 to PNG8 via Photoshop will fix
I just found this in some old code, and I'm not sure what it
I just found out that my program is losing 5% execution speed when it
I’ve just found out that the execution plan performance between the following two select
I was playing with a project of mine today and found an interesting little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.