views:

47

answers:

2

I created a HTML application and I want it to look to see if it's the latest version and then if it is not then show a link.

I'm a beginner to javaScript so if you could tell me how to fix this code that would be great.

<script type="text/javascript">
var thisVersion = 1.5

function checkForUpdate() {
    document.getElementById("version").value;
    if (value == > "thisVersion")
     updateMessage.style.display = 'block'
    else
     updateMessage.style.display = 'none'
}
</script>

<iframe src="my page where i say the latest version" scrolling="no" width="0" height="0" style="display:none"></iframe>

<table id="updateMessage" style="display:none">
There is a new version avalabal please download the new verion
<input type="button" value="here" src="update page">
</table>

Thanks

A: 

It's not going to be possible for a HTML page on the user's hard drive to automatically check for and/or download a new version with Javascript. For security reasons, Javascript cannot access iframes from different domains, and AJAX won't work for the same reason. Internet Explorer always displays a warning about Javascript too, which is annoying for users.

One solution is to just keep the page hosted online, since you're going to be checking online anyway.

An alternative is for the downloaded HTML page to display a hosted script, passing its current version in the URL. So if the file the user downloads is version 2, the iframe would look like this:

<iframe src="http://yoursite.com/checkupdate.php?current=2"&gt;&lt;/iframe&gt;

Then the checkupdates.php script in the iframe would check the value of 'current' passed into it. If your current version is 2, it could output "You are using the latest version". But if your current version is 3, it could display "There is a newer version of this file - click here to download it".

Then the version 3 of the page would have this iframe instead:

<iframe src="http://yoursite.com/checkupdate.php?current=3"&gt;&lt;/iframe&gt;

Note: you can style the iframe to remove the borders/scrollbars if you want it to look more "inline".

DisgruntledGoat
A: 

Instead of having an iframe that contains a web page with the "latest version" info, you could have a script tag that points to a js on your web server that has the newest version set in a variable:

Content of version.js on your web server:

var latestVersion = 1.5;

html in the downloaded page:

<script type="text/javascript" src="http://yoursite.com/version.js"&gt;&lt;/script&gt;
<script type="text/javascript">
var thisVersion = 1.4;
function checkForUpdate() {

    if (thisVersion < latestVersion )
        updateMessage.style.display = 'block';
    else
        updateMessage.style.display = 'none';
}
</script>
awe