Jquery which event is better than this?

2019-08-12 17:34发布

问题:

I have a page in html (parent page) that have inside an iframe. When you navigate inside iframe (reload iframe's page or click on link) the parent page remains in its previous position. So i used scrollTop to bring back at the top the page.

All works fine but jquery do it only when the iframe is completely loaded (image inluded..) so this is not well...

How can i scrollTop (PARENT PAGE) before the iframe's page is completely loaded?

Parent page body code:

<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
    $('iframe').load(function(){
         $(window).scrollTop(0);
    });
});</script>
<iframe frameborder="0" height="1000" id="iframe" src="http://mysite.com" width="800"></iframe>

Thanx!!!

回答1:

I think you could just do this :

<script type="text/javascript">

jQuery(document).ready(function() {

         $(window).scrollTop(0);
    });
</script>


回答2:

perhaps?

$('iframe').ready(function(){
     $(window).scrollTop(0);
});


回答3:

This should work if I'm reading you correctly:

$('.mylink').click(function(){
 $('html, body').scrollTop(0);
 $('#iframe1').attr('src', 'http://some-other-url');
 window.frames["iframe1"].location.reload();
});