ruegen Posted November 23, 2005 Share Posted November 23, 2005 I have a problem getting my code to open a weblink. What am I doing wrong? }function openLink(url){ if(window.widget){ closeDesc(); widget.openURL(url); } else{ window.location = url; } Link to comment Share on other sites More sharing options...
Chocolate570 Posted November 23, 2005 Share Posted November 23, 2005 You need an extra } at the bottom of the function. You're missing one. Link to comment Share on other sites More sharing options...
hacknsack Posted November 23, 2005 Share Posted November 23, 2005 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 More sharing options...
Jack McKalling Posted November 23, 2005 Share Posted November 23, 2005 Yes, Choco is right any javascript that is beneath this script, will be ignored if present, causing errors :)What is the upmost } for anyway? Link to comment Share on other sites More sharing options...
hacknsack Posted November 23, 2005 Share Posted November 23, 2005 Gosh Dan,Gonna take you a while to hop the rest of the threads here.Better get you a cup of coffee. Link to comment Share on other sites More sharing options...
Jack McKalling Posted November 23, 2005 Share Posted November 23, 2005 After I beat the TOP 1 poster,THEN I get a cup of coffee :)(I do not do such as spamming though, I actually keep helping every one) Link to comment Share on other sites More sharing options...
Chocolate570 Posted November 23, 2005 Share Posted November 23, 2005 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 More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 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. <{POST_SNAPBACK}> Thanks but it still doesn't work Link to comment Share on other sites More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 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 More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 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 More sharing options...
Jack McKalling Posted November 24, 2005 Share Posted November 24, 2005 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 More sharing options...
hacknsack Posted November 24, 2005 Share Posted November 24, 2005 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, Link to comment Share on other sites More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 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,<{POST_SNAPBACK}> 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 More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 Many thanks! (still need help though) Link to comment Share on other sites More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 I now get "TypeError - Object (result of expression openLink) does not allow calls"I don't get it in my editor but when I test it the link doesn't work. Link to comment Share on other sites More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 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 More sharing options...
Chocolate570 Posted November 24, 2005 Share Posted November 24, 2005 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 More sharing options...
ruegen Posted November 24, 2005 Author Share Posted November 24, 2005 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<{POST_SNAPBACK}> This might help? Link to comment Share on other sites More sharing options...
hacknsack Posted November 25, 2005 Share Posted November 25, 2005 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now