Well, I have the following problem: I am building a chat page, I am already receiving good messages, but when I enter this chat page I wanted it to automatically go down to the bottom of the page, where the most recent messages would be.
Follow 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 the parent.scroll (0, 10000); it will come down to the end of one in a second, however I want to go only the 1st time the page is accessed. Would there be another way to stop this function without being the one I'm using? (Detail, this form used by me is not working and, also, I could not stop it with a return or break.)