3
Well, I have the following problem: I’m building a chat page, I’m already getting good messages, only when entering this chat page I wanted to automatically descend to the bottom of the page, in case, where would be the latest messages.
Follows the code:
function ajax(){
var req = new XMLHttpRequest();
req.onreadystatechange = function(){
if (req.readyState == 4 && req.status == 200) {
document.getElementById('mensagens').innerHTML = req.responseText;
}
}
req.open('GET', 'mensagens.php', true);
req.send();
final();
}
setInterval(function(){ajax();}, 1000);
var x = 0;
function final(){
if(x == 0){
parent.scroll(0, 10000);
x++;
}
}
If I remove this if (from the final function) leaving only Parent.scroll(0, 10000); it will go down at the end of one in a second, but I want to go only at 1° once the page is accessed. Is there any other way to stop this function than the one I’m using? (Detail, this form used by me is not working and, also, could not stop it with a Return or break).
It didn’t work either
– Higor Cardoso
Thank you all for your help, but I’m giving up this function. I’m not very good with JS even, so I’ll just leave a floating button to go down at the end when clicked, it’s not quite what I wanted, but it will work at least.
– Higor Cardoso
Run the example and see that it works. But try the following: increase the time of
10
for500
, or increase to1000
.– Sam
Man, thanks a lot. Your code solved
– Higor Cardoso