I am trying to call a JavaScript function after load...like totally after the page loads. It's part of a chatroom I'm designing, in which a cron repeatedly checks for new data, and if there's new data, it tells the chatroom index.php
that there's new data. The page then prints some javascript, but the page has already loaded. How do I call the functions and lines of execution after the page has loaded? Thanks so much in advance!
EDIT: Here's the code:
if($connection) {
$sql = "SELECT * FROM `refresh` WHERE `refresh`=1;";
$query = mysqli_query($connection, $sql);
$result = mysqli_fetch_fields($query);
if($result !== null) {
?>
<script type="text/javascript">
refreshChat();
$.ajax({url: "chat.log", type: "POST"})
.done(function (data) {
$("#chattxt").html(data);
});
</script>
<?php
}
}
//More code irrelevant to this problem.
The JavaScript function refreshChat()
is simply the same code I put after the call to it. I have also tried heredoc, and it didn't work either.