Jump to content

Help - need to open link


ruegen

Recommended Posts

ruegen,We are assuming that your openURL method points to "window.open()" the function that opens a new window(in JavaScript).

<script type="text/javascript">function wControl(){this.openURL = function(url, t, a){  window.open(url, t, a);  }}widget = new wControl();function openLink(url){if(window.widget){ //closeDesc(); widget.openURL(url);}else{ window.location = url;}}openLink("http://www.w3schools.com","_blank");</script>

Here's a link(example) just in case you need it:http://www.w3schools.com/js/tryit.asp?file...s_openallwindowOf course, we have no idea what the "closeDesc()" does.Thanks,

Link to comment
Share on other sites

Oh ya? Well, you better put that coffee away. :)And it works if you fix up the { and }'s. So go fix that up, person who's name i'm too lazy to copy and paste. :)

Link to comment
Share on other sites

In the HTML file I have

<a id="updateLink" href="javascript:openLink('WEBPAGE');" style="text-decoration: none; display: block;">	<div id="newUpdate">  New Update<br />Available!	</div></a>

What I need in the javascript file is when a downloaded txt file (which has the new version number) is not the same as on the javascript file then it displays the above code.When that is displayed you can then click on "new update available" and it "openlink" to a webpage".Does anyone know of a chat room where I can discuss this with someone?NOTE: I removed the real web link with WEBPAGE just for this post.

Link to comment
Share on other sites

currently I have in the javascript file (file.js)

{var currentVersion = "1.0";}{function checkForUpdate(){		var updateRequest = new XMLHttpRequest();  updateRequest.onreadystatechange = nullFunction;  updateRequest.open("GET", "http://site/updaters/update_v.txt", false);   updateRequest.send(null);			var updateRequestText = updateRequest.responseText;		if(updateRequestText == (currentVersion)){ 	 document.getElementById('newUpdate').style.display = 'none'; }

Link to comment
Share on other sites

Please remember next time to edit your previous post, instead of double (or tripple) posting.Next, fix the standalone curly brackets, in your file.js. A javascript file can't begin with a bracket, unless this is a cut-off from the original content :)

Link to comment
Share on other sites

This thread is going to go forever unless you show us the whole page( or at least all of the javascript )..Not being rude, it's just not possible to help you properly without the code :) Thanks,

Hey the link works, always the simplest things.Now I just have to work out how to make the link disappear and only appear when my app needs updating.
Link to comment
Share on other sites

I now looks like this:

var currentVersion = "1.0";function checkForUpdate(){		var updateRequest = new XMLHttpRequest();    updateRequest.open("GET", "http://site/updaters/update_v.txt", false);   updateRequest.send(null);			var updateRequestText = updateRequest.responseText;		if(updateRequestText == (currentVersion)){ 	 document.getElementById('newUpdate').style.display = 'none'; }}function openLink(url){	if(window.widget){    widget.openURL(url);	}	else{  window.location = url;	}}

Link to comment
Share on other sites

Please, I beg of you to edit your previous post before posting a new one. It'll make this topic easier to read. Thanks.I would help, but I don't know the XML or whatever language that is. :)Choco

Link to comment
Share on other sites

OK, still don't know what the window widget is so I made my own for the example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>  <meta http-equiv="content-type" content="text/html; charset=windows-1250">  <title></title>  <script type="text/javascript">  var currentVersion = "1.0";  var xmlhttp;  function checkForUpdate(){  //var url = "http://site/updaters/update_v.txt";  var url = 'testvar.txt';  // code for Mozilla, etc.    if (window.XMLHttpRequest)  {  xmlhttp=new XMLHttpRequest();  xmlhttp.onreadystatechange=xmlhttpChange;  xmlhttp.open("GET",url,true);  xmlhttp.send(null);  }  // code for IE  else if (window.ActiveXObject)  {  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");    if (xmlhttp)    {    xmlhttp.onreadystatechange=xmlhttpChange;    xmlhttp.open("GET",url,true);    xmlhttp.send();    }    }  }  function xmlhttpChange()  {  // if xmlhttp shows "loaded"  if (xmlhttp.readyState==4)  {  // if "OK"    if (xmlhttp.status==200)      {        if(parseFloat(currentVersion) == parseFloat(xmlhttp.responseText)){          document.getElementById('newUpdate').style.display = 'none';          }      }    else      {        alert("Version Request Error-Please Refresh")      }    }  }  function wControl(){  this.openURL = function(url, t, a){      window.open(url, t, a);      }  }    widget = new wControl();  function openLink(url){  if(window.widget){    widget.openURL(url);    }  else{  window.location = url;    }  }  </script>  </head>  <body onload="checkForUpdate()">  <div id="newUpdate">    <a id="updateLink" href="java script:openLink('testvar.txt');"      style="text-decoration: none; display: block;">      New Update<br />Available!        </a>  </div>  </body></html>

Recommendation:You could do this with a straight script source like:

<script type="text/javascript" src="testvar.txt"></script>

Thanks,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...