<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<!-- JQuery code -->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- Script which refreshes each element every 5 seconds -->
<script>
setInterval(reloadElements, 5000);
function reloadElements() {
$('#refresh').load(location.href+' #refresh');
}
</script>
</head>
<body>
<p id="refresh">
This is some paragraph text. <br />
<ul>
<li> List item one. </li>
<li> List item two. </li>
</ul>
</p>
</body>
</html>
This HTML file will always reside locally on the client.
The whole reason I wrote this script was so that my page can automatically reflect changes made to the file (i.e. I shouldn't be required to manually refresh the page). I have a C++ application which writes to this HTML file (only changes the content of the <p id="refresh">
tag).
My test machine is running Windows XP 32 bit.
Behaviour on Google Chrome, Version 26.0.1410.64 m:
When I run Chrome with the --allow-file-access-from-files
parameter and without any command line arguments and modified the .html file using a text editor, the changes did not get displayed on the browser.
Behaviour on Internet Explorer, Version 8.0.6001.18702, Mozilla Firefox, Version 20.0.1:
Modification of only the paragraph text works (i.e. the changes are reflected). Modifying the list elements or adding anything after the list doesn't get reflected.
Behaviour on JS Bin:
As expected, after opening the web page and modifying the .html file using a text editor, the changes were reflected on the browser when the 5 second interval expired.
I currently need only support Internet Explorer, Google Chrome and Mozilla Firefox.
Why is there this difference? What am I doing wrong? Is there a better way to achieve what I want?
PS: This happens to be my first web-page code.
UPDATE:
I fixed the Firefox and Internet Explorer issues thanks to the helpful suggestions of squint (see comments below). I basically put the contents of the <p>
element in a separate .html file and I modified the JQuery load to load that file. Don't know how this makes a difference though.
` element. Is that possible?
– Anish Ramaswamy May 07 '13 at 05:50