S Murder Posted April 26, 2007 Share Posted April 26, 2007 checkURL() is called in the constructor. //Constructor //Called every half second to see if the url has changed checkURL: function() { alert("checked URL"); var paramStr = this.getParams(); var URLHashStr = this.getURLHash(); //if there was a change if(paramStr != URLHashStr) { this.onhashchange(params, URLHashStr.toQueryParams); this.setParams(URLHashStr); } } //Constructor initialize: function() { //alert("initialized"); //make shift Event Detection. //checkURL method will be called regularly //every half second, appearing to the user //as an instantaneous event setInterval("this.checkURL()", 500); } When I use setInterval("this.checkURL", 500); the checkURL method is called once, and that's it. But if I use any other syntax ("this.checkURL()", this.checkURL, this.checkURL()) I get a new error every half second saying the method doesn't exist. How do I get this to work? Link to comment Share on other sites More sharing options...
jesh Posted April 26, 2007 Share Posted April 26, 2007 Oh, I can't remember exactly how to solve this - aspnetguy knows, I think - but I might be able to help. When you use setInterval and setTimeout, you cannot use "this" to reference the current object.Try this instead: var that = this;setInterval(function() { that.checkURL(); }, 500); Maybe aspnetguy (or someone else) will come by and tell me how wrong I am. Link to comment Share on other sites More sharing options...
pulpfiction Posted April 26, 2007 Share Posted April 26, 2007 This should help...http://www.faqts.com/knowledge_base/view.p...id/2311/fid/128 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.