I want to do a conditional refresh of a page. I understand that you can do a refresh with the javascript function location.reload();.
Consider the link first - http://www.top-5000.nl/pgn4web/live1.htm
If a game is finished I want the page to refresh. Using JAVA only one check is needed, if the file size of the game suddenly becomes smaller then that's a new game, the condition is met, then do the refresh. I have no idea how to do this check.
--------
I could solve the problem in C using TASKKILL with PID terminating the browser and then starting the browser again from C but I fear that will be not very pleasing for the eye.
Any JAVA experts around?
Moderator: Ras
-
Rebel
- Posts: 7493
- Joined: Thu Aug 18, 2011 12:04 pm
- Full name: Ed Schröder
-
Henk
- Posts: 7251
- Joined: Mon May 27, 2013 10:31 am
Re: Any JAVA experts around?
Is this about JAVA or javascript ? By the way I don't know anything about JAVA. I also don't understand the question if it is about javascript for you gave the answer yourself that you can use location.reload().
??
??
-
Rebel
- Posts: 7493
- Joined: Thu Aug 18, 2011 12:04 pm
- Full name: Ed Schröder
Re: Any JAVA experts around?
I didn't even know that there is a difference so my ignorance is even worse than yours.
-
Rebel
- Posts: 7493
- Joined: Thu Aug 18, 2011 12:04 pm
- Full name: Ed Schröder
Re: Any JAVA experts around?
The question is how to do a file size check.Henk wrote:Is this about JAVA or javascript ? By the way I don't know anything about JAVA. I also don't understand the question if it is about javascript for you gave the answer yourself that you can use location.reload().
??
-
smatovic
- Posts: 3536
- Joined: Wed Mar 10, 2010 10:18 pm
- Location: Hamburg, Germany
- Full name: Srdja Matovic
Re: Any JAVA experts around?
Dunno about Java,
but jQuery, a Javascript Framework offers comfortable Ajax calls.
You could do an Ajax call from the web-browser to an given url every n seconds and check for the condition and then reload the whole page.
Or you could simply reload the content of one div element every n seconds or so.
Change the text of a <div> element using an AJAX request
http://www.w3schools.com/jquery/ajax_ajax.asp
Call jQuery Ajax Request Each X Minutes
http://stackoverflow.com/questions/4930 ... es#4930470
Do an conditional reload with jQuery
http://stackoverflow.com/questions/8899 ... al#8899777
--
Srdja
but jQuery, a Javascript Framework offers comfortable Ajax calls.
You could do an Ajax call from the web-browser to an given url every n seconds and check for the condition and then reload the whole page.
Or you could simply reload the content of one div element every n seconds or so.
Change the text of a <div> element using an AJAX request
http://www.w3schools.com/jquery/ajax_ajax.asp
Call jQuery Ajax Request Each X Minutes
http://stackoverflow.com/questions/4930 ... es#4930470
Do an conditional reload with jQuery
http://stackoverflow.com/questions/8899 ... al#8899777
--
Srdja
-
casaschi
- Posts: 164
- Joined: Wed Dec 23, 2009 1:57 pm
Re: Any JAVA experts around?
I'm not sure what you are trying to accomplish, but you can't really do a file size check in javascript.Rebel wrote:The question is how to do a file size check.
However, pgn4web stores data from the PGN file in two arrays: pgnGame[] and pgnHeader[], one array entry each for each game in the PGN file. Looking at those you can possibly trigger a page reload on demand.
In general however, using a page reload with javascript should only be a very last resort, in case something went badly wrong and you are out of control. For anything else, you should be able to cope with normal javascript code.
Last edited by casaschi on Mon May 09, 2016 1:01 pm, edited 1 time in total.
-
hgm
- Posts: 28461
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Any JAVA experts around?
Java and JavaScript are different languages. JavaScript is an extension of HTML built into most web browsers. Java needs a special plugin as an interpreter, and doesn't interact directly with the browser and the HTML (AFAIK).
Normally in JavaScript you would put a downloaded file in a variable (as a text string), and you could use the variable.length method to determine the number of characters in it (and compare it with the remembered length of the previous download in an if-statement).
Normally in JavaScript you would put a downloaded file in a variable (as a text string), and you could use the variable.length method to determine the number of characters in it (and compare it with the remembered length of the previous download in an if-statement).
-
Henk
- Posts: 7251
- Joined: Mon May 27, 2013 10:31 am
Re: Any JAVA experts around?
Usually a server checks the file size and returns a view or HTML string which is displayed in the browser. Server may use JAVA.
Or maybe client requests file size to the server. I don't know. Web applications usually use databases instead of files.
Or maybe client requests file size to the server. I don't know. Web applications usually use databases instead of files.
-
Rebel
- Posts: 7493
- Joined: Thu Aug 18, 2011 12:04 pm
- Full name: Ed Schröder
Re: Any JAVA experts around?
I got that in the mean timehgm wrote:Java and JavaScript are different languages. JavaScript is an extension of HTML built into most web browsers. Java needs a special plugin as an interpreter, and doesn't interact directly with the browser and the HTML (AFAIK).
Yep, that.Normally in JavaScript you would put a downloaded file in a variable (as a text string), and you could use the variable.length method to determine the number of characters in it (and compare it with the remembered length of the previous download in an if-statement).
-
Rebel
- Posts: 7493
- Joined: Thu Aug 18, 2011 12:04 pm
- Full name: Ed Schröder
Re: Any JAVA experts around?
I am testing a live broadcast of 4 games (channel 1-4) and at the same time maintain a live ranking as you can see from the link I gave. So if a new game is started I want to automatically refresh the page that shows the new ranking.casaschi wrote:I'm not sure what you are trying to accomplish, but you can't really do a file size check in javascript.Rebel wrote:The question is how to do a file size check.
However, pgn4web stores data from the PGN file in two arrays: pgnGame[] and pgnHeader[], one array entry each for each game in the PGN file. Looking at those you can possibly trigger a page reload on demand.
In general however, using a page reload with javascript should only be a very last resort, in case something went badly wrong and you are out of control. For anything else, you should be able to cope with normal javascript code.