Nomax5 Posted September 24, 2006 Share Posted September 24, 2006 Hi I have a large number of pages with ajax based chat on and I want to stop it communicating when the window looses focus using javascript I’ve almost got it working but there is a bug.It stops communicating when the window looses focus but when the window gets focus again it speeds up communicating, doubles it I think. I would be grateful for any help . This is the controlling javascript [code]<? sajax_show_javascript();?> var check_n = 0; var old_sha1 = ""; var new_sha1 = ""; <!-- Variable to check if window has focus --> var hasFocus = 1; window.onfocus = function() { hasFocus = 1; refresh(); } window.onblur = function() { hasFocus = 0; } function refresh_cb(new_data) { new_sha1 = hex_sha1(new_data); if(old_sha1 != new_sha1) { document.getElementById("wall").innerHTML = new_data; old_sha1 = new_sha1; } document.getElementById("status").innerHTML = "Refreshed: #" + check_n; check_n++; setTimeout("refresh()", <?php echo $cfg['refreshrate'] ; ?>); } function refresh() { if(hasFocus == 1) { x_refresh(refresh_cb); } } function add_cb() { // we don't care.. } function add() { var line; var handle; handle = document.getElementById("handle").value; line = document.getElementById("line").value; x_add_line("[" + handle + "] %spantag%" + line, add_cb); document.getElementById("line").value = ""; // document.getElementById("line").focus(); } // ]]> </script>[/code]I’ve been using some code called chatwall from http://www.laan.org/demos/chatwall/ For quite some time.it works great and is really small in kb's cheers Link to comment https://forums.phpfreaks.com/topic/21856-start-and-stop-ajax-onfocus-bug-help/ Share on other sites More sharing options...
fenway Posted September 25, 2006 Share Posted September 25, 2006 So this isn't your code? Link to comment https://forums.phpfreaks.com/topic/21856-start-and-stop-ajax-onfocus-bug-help/#findComment-97952 Share on other sites More sharing options...
Nomax5 Posted September 27, 2006 Author Share Posted September 27, 2006 no it's from a guy called Joop Laan and it in turn uses sajax toolkit from modernmethod.com he's gone gone over to using ruby rails but I like this old version because it's really small and simple. but as I said I'm trying to get it to stop communicating when the window looses focus. Link to comment https://forums.phpfreaks.com/topic/21856-start-and-stop-ajax-onfocus-bug-help/#findComment-99325 Share on other sites More sharing options...
fenway Posted September 27, 2006 Share Posted September 27, 2006 I can't really help here -- there are functions that I don't see, and I don't have the time to figure out how they might work. Link to comment https://forums.phpfreaks.com/topic/21856-start-and-stop-ajax-onfocus-bug-help/#findComment-99772 Share on other sites More sharing options...
Nomax5 Posted September 28, 2006 Author Share Posted September 28, 2006 I have the functions they're quites small I didn't post them because I don't think its what the functions are doing its when they're calledwhen using IE it works fine as far as I can tell I open 2 windows side by side and as I move focus between them I can see the refresh counter stop and startBut with firefox the counter doubles up like running twice as fast Link to comment https://forums.phpfreaks.com/topic/21856-start-and-stop-ajax-onfocus-bug-help/#findComment-100158 Share on other sites More sharing options...
fenway Posted September 28, 2006 Share Posted September 28, 2006 Clearly, there's a difference in the way the browsers handle focus... that's about all I can say. Link to comment https://forums.phpfreaks.com/topic/21856-start-and-stop-ajax-onfocus-bug-help/#findComment-100310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.