title: JavaScript not reloading in Android webview?
body: <p>I have made a simple webview application that pulls this HTML page that uses PHP and JavaScript: <a href="http://s-ka-paidbeats.com/app_tree/randomword/5.html" rel="nofollow noreferrer">http://s-ka-paidbeats.com/app_tree/randomword/5.html</a><br></p>
  
  <p>The problem is that the JavaScript is not refreshing on my mobile device and I can't figure out why!<br></p>
  
  <p>When I test the page on my desktop web browser it works fine sometimes but the page just never refreshes and the words stay the same. On my Android phone the word do not update or refresh at all and I can't figure out why this is happening.</p>
  
  <p>Here is the actual page users view (the 5.html file):</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/JavaScript"&gt;
        function timedRefresh(timeoutPeriod) {
          setTimeout("location.reload(true);",timeoutPeriod);
        }
        window.onload = timedRefresh(7000);
      &lt;/script&gt;
      &lt;title&gt;Freestyle Word Generator - 5 Seconds&lt;/title&gt;
      &lt;style type="text/css"&gt;
        body, td, p, input {
          color : #000000;
          font-family: Impact, Haettenschweiler, 'Franklin Gothic Bold', Charcoal, 'Helvetica Inserat', 'Bitstream Vera Sans Bold', 'Arial Black', 'sans serif';
          font-size : 12px;
        }
        .button {
          background-color: #f44336;
          border: none;
          color: white;
          padding: 15px 32px;
          text-align: center;
          text-decoration: none;
          display: inline-block;
          font-size: 16px;
        } /* Red */ 
      &lt;/style&gt;
      &lt;link rel="stylesheet" href="app1.css"&gt;
    &lt;/head&gt;
    &lt;body style="background-color:#000000;text-align:center;color:#fff"&gt;
      &lt;div class="w3-container w3-orange"&gt;
        &lt;h1 style="text-align: center;margin:0px;margin-top:15px;font-family: Impact, Haettenschweiler, 'Franklin Gothic Bold', Charcoal, 'Helvetica Inserat', 'Bitstream Vera Sans Bold', 'Arial Black', 'sans serif';"&gt;Freestyle Word Generator&lt;/h1&gt;
        &lt;p style="text-align:center;margin:0px;margin-bottom:15px;font-family: Impact, Haettenschweiler, 'Franklin Gothic Bold', Charcoal, 'Helvetica Inserat', 'Bitstream Vera Sans Bold', 'Arial Black', 'sans serif';font-size : 16px;"&gt;Sharpen Your Skills!&lt;/p&gt;
      &lt;/div&gt;
      &lt;p style="color:#ff9800;font-size:30px;margin-bottom:0px;"&gt;YOUR WORD IS:&lt;/p&gt;
      &lt;p style="color:#fff;font-size : 30px;margin-top:5px;"&gt;&lt;script type="text/javascript" src="randomword.php?type=1"&gt;&lt;/script&gt;&lt;/p&gt;
      &lt;script&gt;
        function startTimer(duration, display) {
        var timer = duration, minutes, seconds;
        setInterval(function () {
            minutes = parseInt(timer / 60, 10)
            seconds = parseInt(timer % 60, 10);
  
            minutes = minutes &lt; 10 ? "0" + minutes : minutes;
            seconds = seconds &lt; 10 ? "0" + seconds : seconds;
  
            display.textContent = minutes + ":" + seconds;
  
            if (--timer &lt; 0) {
                timer = duration;
            }
        }, 1000);
        }
        window.onload = function () {
        var fiveMinutes = 5 * 1,
            display = document.querySelector('#time');
        startTimer(fiveMinutes, display);
        };
      &lt;/script&gt;
      &lt;div style="color:#555;"&gt;New Word In &lt;span id="time"&gt;00:05&lt;/span&gt; Seconds!&lt;/div&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;input type="button" style="background-color: #ff9800;border: none;color: black;padding: 15px 32px;text-align: center;text-decoration: none;display: inline-block;font-size: 20px;" onclick="location.href='http://s-ka-paidbeats.com/app_tree/randomword/index.php';" value="STOP" /&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my Android class data:</p>
  
  <pre><code>package com.randomword.app.randomword;
  import android.annotation.SuppressLint;
  import android.app.AlertDialog;
  import android.app.ProgressDialog;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.text.Html;
  import android.view.Gravity;
  import android.view.KeyEvent;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.webkit.WebChromeClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.TextView;
  import android.support.v7.widget.Toolbar;
  import android.widget.Toast;
  import com.randomword.app.randomword.NetorkConnection;
  @SuppressLint("SetJavaScriptEnabled")
  public class Beats extends AppCompatActivity {
  
  private WebView webView;
  NetorkConnection ntwrk_con = new NetorkConnection(this);
  ProgressDialog dialog;
  
  
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
      TextView toolsresources5 = (TextView)findViewById(R.id.feedbacktextview);
      toolsresources5.setVisibility(View.INVISIBLE);
  
  
  
  
  
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      webView = (WebView) findViewById(R.id.activity_main_webview);
  
  
  
      dialog = new ProgressDialog(Beats.this);
  
  
      if (ntwrk_con.isConnectingToInternet()) {
  
          webView();
  
      } else {
          dialog_box_for_internet();
      }
  
  }
  
  public void dialog_box_for_internet() {
      if (ntwrk_con.isConnectingToInternet()) {
  
          webView();
  
      } else {
          // dismis_dialog_box_for_internet = true;
          AlertDialog.Builder builder = new AlertDialog.Builder(
                  Beats.this);
          LayoutInflater inflater = getLayoutInflater();
          View view = inflater.inflate(R.layout.dialog_custom_titile, null);
          TextView title = (TextView) view.findViewById(R.id.myTitle);
          title.setText("Unable To Connect");
          builder.setCustomTitle(view);
          builder.setMessage("No Internet Connection")
                  .setCancelable(false)
                  .setPositiveButton("Retry",
                          new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog,
                                                  int id) {
                                  if (ntwrk_con.isConnectingToInternet()) {
  
                                      webView();
  
                                  } else {
                                      new Thread_for_internet().execute();
                                  }
                                  // dialog.cancel();
                              }
                          })
                  .setNegativeButton("Okay",
                          new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog,
                                                  int id) {
                                  finish();
  
                                  // Gridview.super.onBackPressed();
                              }
                          });
  
          AlertDialog alert = builder.create();
          alert.show();
      }
  }
  
  class Thread_for_internet extends AsyncTask&lt;String, Void, Boolean&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          dialog.setMessage("Loading..Please wait.");
          dialog.setCanceledOnTouchOutside(false);
          dialog.show();
  
      }
  
      @Override
      protected Boolean doInBackground(String... args) {
  
          try {
  
              Thread.sleep(2000);
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return null;
  
      }
  
      protected void onPostExecute(Boolean result) {
          dialog.dismiss();
          dialog_box_for_internet();
  
      }
  
  }
  
  public void webView() {
      webView.setWebViewClient(new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {
              if (dialog.isShowing()) {
                  dialog.dismiss();
              }
          }
      });
      dialog.setMessage("Picking Yes Or No...\nOne Moment...");
      dialog.setCanceledOnTouchOutside(false);
      dialog.show();
  
      webView.getSettings().setJavaScriptEnabled(true);
      webView.getSettings().setDomStorageEnabled(true);
      webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
      webView.getSettings().setLoadsImagesAutomatically(true);
      webView.setWebChromeClient(new WebChromeClient());
  
  
      webView.loadUrl("http://s-ka-paidbeats.com/app_tree/randomword/5.php?nocache=1");
  
      WebSettings webSettings = webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webSettings.setDomStorageEnabled(true);
      webSettings.setLoadsImagesAutomatically(true);
  
  
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (event.getAction() == KeyEvent.ACTION_DOWN) {
          switch (keyCode) {
              case KeyEvent.KEYCODE_BACK:
                  if (webView.canGoBack()) {
                      webView.goBack();
                  } else {
                      finish();
                  }
                  return true;
          }
  
      }
      return super.onKeyDown(keyCode, event);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      boolean bRet=false;//set true is menu selection handled
      switch (item.getItemId()) {
          case R.id.action_settings_3:
              Toast.makeText(this, Html.fromHtml("&lt;big&gt;&lt;b&gt;Develeped By S-Ka-Paid&lt;/b&gt;&lt;/big&gt;&lt;br&gt;© 2016 S-Ka-Paid"), Toast.LENGTH_LONG).show();
              bRet=true;
              break;
          case R.id.action_settings_4:
              Intent intent2 = new Intent(Intent.ACTION_VIEW);
              //Try Google play
              intent2.setData(Uri.parse("market://details?id=com.yesorno.app.yesorno"));
              startActivity(intent2);
              bRet=true;
              break;
          default:
              bRet=super.onOptionsItemSelected(item);
      }
      return bRet;
  }
  }
  </code></pre>
  
  <p>If you visit the page: <a href="http://s-ka-paidbeats.com/app_tree/randomword/5.php" rel="nofollow noreferrer">http://s-ka-paidbeats.com/app_tree/randomword/5.php</a> on a desktop sometimes it works and sometimes the browser will not change the random word after the first word..... I'm thinking it has something to do with browser caching or something I'm not sure.</p>