Any JAVA experts around?

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Rebel
Posts: 7493
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Any JAVA experts around?

Post by Rebel »

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.
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: Any JAVA experts around?

Post by Henk »

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().

??
User avatar
Rebel
Posts: 7493
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Re: Any JAVA experts around?

Post by Rebel »

I didn't even know that there is a difference so my ignorance is even worse than yours.
User avatar
Rebel
Posts: 7493
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Re: Any JAVA experts around?

Post by Rebel »

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().

??
The question is how to do a file size check.
smatovic
Posts: 3536
Joined: Wed Mar 10, 2010 10:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic

Re: Any JAVA experts around?

Post by smatovic »

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
casaschi
Posts: 164
Joined: Wed Dec 23, 2009 1:57 pm

Re: Any JAVA experts around?

Post by casaschi »

Rebel wrote:The question is how to do a file size check.
I'm not sure what you are trying to accomplish, but you can't really do a file size check in javascript.
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.
User avatar
hgm
Posts: 28461
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Any JAVA experts around?

Post by hgm »

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).
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: Any JAVA experts around?

Post by Henk »

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.
User avatar
Rebel
Posts: 7493
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Re: Any JAVA experts around?

Post by Rebel »

hgm 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).
I got that in the mean time :wink:
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).
Yep, that.
User avatar
Rebel
Posts: 7493
Joined: Thu Aug 18, 2011 12:04 pm
Full name: Ed Schröder

Re: Any JAVA experts around?

Post by Rebel »

casaschi wrote:
Rebel wrote:The question is how to do a file size check.
I'm not sure what you are trying to accomplish, but you can't really do a file size check in javascript.
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.
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.