Scroll to top from iframe
I want to call jquery to jump to top from iframe.
<script>
$(document).ready(function() {
window.parent.$("bo开发者_开发百科dy,html").animate({scrollTop:0}, 'slow');
});
</script>
Doesn't work..
//On same domain...
If the iframe
is in the same domain as parent then try this
$(document).ready(function() {
$("body,html", window.parent).animate({scrollTop:0}, 'slow');
});
window.parent.$("body,html")
will use window.parent.$
jQuery object but will still look for element inside iframe
because you are not specifying the context here.
It's probably because it's restriction of Same Origin Policy. This is not possible if you're on same domain.
If it's on same domain, try to change
window.parent.$("body,html")
to
$("body,html", window.top)
I don't know in JQuery but in simply JS here worked with this:
parent.scroll(0, 0)
To load to top iframe in main page you should write your javascript function.
function loadToTop() {
parent.self.scrollTo(0, 0);
}
It worked! Let's enjoy
精彩评论