Php 如何在iframe中的ajax请求后滚动到顶部?
我在iframe中有以下jQuery代码:Php 如何在iframe中的ajax请求后滚动到顶部?,php,jquery,Php,Jquery,我在iframe中有以下jQuery代码: <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: "; $
<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>
jQuery(“#logBtn”)。单击(函数(){
jQuery(“#content promo”).load(“/path/to/file.php”,函数(响应、状态、xhr){
如果(状态=“错误”){
var msg=“抱歉,出现错误:”;
$(“#error”).html(msg+xhr.status+“”+xhr.statusText);
}else{//更新
$(“html,body”).animate({scrollTop:0},“slow”);
}
});
返回false;
});
在AJAX请求之后,iframe如何才能滚动回顶部?使用:
$('#my-frame').scrollTop();
您可以使用此代码
window.scrollTo(x-coord,y-coord)代码>
在哪里
我找到了解决办法。我已经将下面的代码添加到file.php
中,现在可以使用了
window.parent.parent.scrollTo(0800)代码>
Parameters
* x-coord is the pixel along the horizontal axis.
* y-coord is the pixel along the vertical axis.