I'm using sweetalert2 script for when a user posts a comment on my site, It scrolls down to their comment and sweet alert pops up but when they click ok on the sweet alert box it scrolls back upto the top.
From what i've been reading i need some sort of preventdefault or something but i can't figure out where that would go?
Here is my script:
<!-- Sweet alert -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.6.8/sweetalert2.min.js"></script>
<script>
window.location.hash = "comment-<?php echo $newcommentid; ?>";
$(document).ready(function () {
swal({
title: "Comment Posted",
text: "Thanks, your comment has now been successfully posted.",
type: "success"
});
});
</script>
Try this