JQuery $('iframe')。准备好了为什么不工作? [英] JQuery $('iframe').ready why doesn't work?

查看:113
本文介绍了JQuery $('iframe')。准备好了为什么不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的父页面里有很长的iframe。当你重新加载或者点击i帧页面中的链接时,它会被加载,但是必须向上滚动纯视窗。



我已经尝试过variuos代码示例: jquery哪个事件比这更好
如何使用iFrame重新加载滚动父页
父母身体代码:

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

现在,这是我在父页面中的最终代码:(不起作用)

 < script type =text / javascript> 
$('iframe')。ready(function(){
$(window).scrollTop(0);
});
< / script>
< iframe frameborder =0height =1000id =iframealign =topsrc =http://foicam.altervista.org/listadinamica.phpwidth =800> ;< / iframe中>

但问题在于每个代码在父框架完成加载之后向上滚动(图片包含)。 Whant我想要的是父页面向上滚动iframe完成加载



如果您点击上一张图片或向下滚动页面然后重新加载只有iframe,你会明白我的意思!

感谢很多,抱歉,但我发现这种语言的存在,昨天下午!

解决方案

将您的代码更改为:

 < iframe frameborder =0height =1000id =iframealign =topsrc =http://foicam.altervista.org/listadinamica.phpwidth =800> ;< / iframe中> 

< script type =text / javascript>
$('iframe')。ready(function(){
$(window).scrollTop(0);
});
< / script>

在您的iframe是您DOM的一部分之前调用您的脚本。如果你的脚本在你的iframe之后是你的DOM的一部分,它会识别它,并且 $('iframe')实际上会找到该对象。


I have a very long iframe inside my parent page. When you reload or click on a link inside i frame's page it is loaded inside it but the purent window must be scroll up.

I have tried variuos code example:jquery which event is better thatn this and How to scroll parent page with iFrame reload 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>

And now this is my final code in parent page: (that doesn't work)

<script type="text/javascript">
$('iframe').ready(function(){
     $(window).scrollTop(0);
});
</script>
<iframe frameborder="0" height="1000" id="iframe" align="top" src="http://foicam.altervista.org/listadinamica.php" width="800" ></iframe>

but the problem is that each code scroll up the parent page AFTER the frame is compleately loaded (images include). Whant i want is that the parent page scrolls up BEFORE iframe has finished to load.

if you click on last image or scroll down the page and then reload only iframe you'll see what i mean!

Thanx a lot, and sorry but I discovered the existence of this language iesterday afternoon!!!

解决方案

Change your code to:

<iframe frameborder="0" height="1000" id="iframe" align="top" src="http://foicam.altervista.org/listadinamica.php" width="800" ></iframe>

<script type="text/javascript">
$('iframe').ready(function(){
     $(window).scrollTop(0);
});
</script>

Your script is being called before your iframe is part of your DOM. If you put your script after your iframe is part of your DOM, it will recognize it and $('iframe') will actually find the object.

这篇关于JQuery $('iframe')。准备好了为什么不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆