简体   繁体   English

asp.net IFrame滚动条推到顶部。 。

[英]asp.net IFrame scroll bar push to top . .

Heres a tricky one . 这是一个棘手的问题。 .

I have a webpage (called PageA) that has a header and then simply includes an iframe. 我有一个网页(称为PageA),该网页具有标题,然后仅包含iframe。 Lets call the page within the iframe PageB. 让我们在iframe PageB中调用该页面。 PageB simply has a bunch of thumbnails but there are a lot so you have to scroll down on PageA to view them all. PageB只是有一堆缩略图,但是缩略图很多,因此您必须向下滚动PageA才能查看所有缩略图。

When i scroll down to the bottom of the pageB and click on a thumbnail it looks like it takes me to a blank page. 当我向下滚动到pageB的底部并单击缩略图时,似乎将我带到空白页。 What actually happens is that it bring up the image but since the page that is just the image is much shorter in height, the scroll bar stays at the same location and doesn't adjust for it. 实际发生的情况是它显示了图像,但是由于只是图像的页面的高度要短得多,因此滚动条停留在相同的位置,并且不会对其进行调整。 I have to scroll up to the top of the page to view the picture. 我必须向上滚动到页面顶部才能查看图片。

Is there anyway when i click a link on a page that is within an iframe, the outer pages scroll bar goes back up to the top 无论如何,当我单击iframe内的页面上的链接时,外部页面滚动条会回到顶部

thks, ak ks

@mek after trying various methods, the best solution I've found is this: 在尝试各种方法之后,@ mek所提供的最佳解决方案是:

In the outer page, define a scroller function: 在外部页面中,定义滚动器功能:

<script type="text/javascript">
  function gotop() {
    scroll(0,0);
  } 
</script>

Then when you define the iframe, set an onload handler (which fires each time the iframe source loads ie whenever you navigate to a new page in the iframe) 然后,当您定义iframe时,设置一个onload处理程序(每次加载iframe源时即在您导航到iframe中的新页面时都会触发)

<iframe id="myframe" 
    onload="try { gotop() } catch (e) {}" 
    src="http://yourframesource"
    width="100%" height="999"
    scrolling="auto" marginwidth="0" marginheight="0" 
    frameborder="0" vspace="0" hspace="0" >
</iframe>

The nice thing about this approach is it means you do not need to make any changes to the pages included in the iframe (and the iframe contents can happily be in another domain - no cross-site scripting issues). 这种方法的优点是,您无需对iframe中包含的页面进行任何更改(iframe的内容可以愉快地位于另一个域中-无需跨站点脚本问题)。

Javascript is your best bet. Javascript是最好的选择。 You can use the scroll() method to scroll back up to the top of your IFRAME. 您可以使用scroll()方法向后滚动到IFRAME的顶部。 Add a javascript handler in the body load so that each time you click a thumbnail, call a function that calls scroll() to scroll up. 在主体负载中添加一个javascript处理程序,以便每次单击缩略图时,调用一个调用scroll()的函数以向上滚动。

I've spent a considerable amount of time trying to figure out how to scroll to the top of the iframe from within the PHP code I was calling (from within the parent ASP.NET page). 我花了很多时间试图弄清楚如何从我正在调用的PHP代码(从父ASP.NET页中)滚动到iframe的顶部。 I never figured I could scroll to the top using the same javascript but in the iframe's onload event. 我从没想过我可以使用相同的JavaScript滚动到顶部,但是在iframe的onload事件中。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM