3

Checking the HTML application for updates

 2 years ago
source link: https://www.codesd.com/item/checking-the-html-application-for-updates.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Checking the HTML application for updates

advertisements

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


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"></iframe>

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"></iframe>

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK