在iframe中,JQuery Mobile自动滚动到iframe顶部 [英] When within iframe JQuery Mobile autoscrolls to the iframe top

查看:475
本文介绍了在iframe中,JQuery Mobile自动滚动到iframe顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用iframe将为jquery mobile开发的网站嵌入常规网站。
到目前为止这是有效的,但是父页面会自动向下滚动到iframe的顶部,这是不希望的,应该被阻止。这是我的代码。



父页面(parent.html):

 < div style =margin-top:1500px> SPACER< / div> 
< iframe src =frame.htmlwidth =660pxframeborder =0scrolling =no>< / iframe>

嵌入页面(frame.html):



< pre class =lang-html prettyprint-override> <!DOCTYPE html>< html lang =de>
< head>
< title>嵌入页面< / title>
< script type =text / javascriptsrc =// ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js\"></script>
< script type =text / javascriptsrc =// code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js\"></script>
< / head>
< body>
这是我的测试
< / body>
< / html>

有任何想法如何解决这个问题?

解决方案

它认为jquery mobile的 focusPage()函数会导致这种滚动效果,所以我最终只是阻止它在里面运行一个iframe。

  if(top!== self){// if iframe iframe 
//不使用focusPage进行嵌入式网站防止自动滚动
$ .mobile.focusPage = function(page){
return;
}
}


I need to embed website developed for jquery mobile to the regular website using iframe. This works so far, but parent page is automatically scrolled down to the top of iframe, which is not desired and should be prevented. Here's the code I have.

Parent Page(parent.html):

<div style="margin-top:1500px">SPACER</div>
<iframe src="frame.html" width="660px" frameborder="0" scrolling="no"></iframe>

Embedded page(frame.html):

<!DOCTYPE html><html lang="de">
<head>
    <title>Embedded page</title>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="//code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>    
</head>
<body>
  THIS IS MY TEST
</body>
</html>

Any thoughts how to solve that?

解决方案

It appreared that jquery mobile's focusPage() function is causing this scroll effect, so I ended up simply preventing it from running when inside an iframe.

if (top!==self) { //if iside iframe
    //don't use focusPage for embedded site to prevent autoscroll
    $.mobile.focusPage = function ( page ) {
        return;
    }
}

这篇关于在iframe中,JQuery Mobile自动滚动到iframe顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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