I have the following jQuery code in an iframe:
<script>
jQuery("#logBtn").click(function(){
jQuery("#content-promo").load("/path/to/file.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}else{ //update
$("html, body").animate({ scrollTop: 0 }, "slow");
}
});
return false;
});
</script>
How can the iframe scroll back to the top after the AJAX-request?
Use:
$('#my-frame').scrollTop();
You can use this code window.scrollTo(x-coord, y-coord);
where
Parameters
* x-coord is the pixel along the horizontal axis.
* y-coord is the pixel along the vertical axis.
I found the solution. I've added the code below to file.php
and it works now.
<script> window.parent.parent.scrollTo( 0, 800 ); </script>