简体   繁体   English

如何在更新面板中从iframe调用父页面javascript

[英]how to call parent page javascript from iframe inside an update panel

What i am trying to do is i want to call a javascript function in the parent page to scroll the window to the TOP. 我想做的是我想在父页面中调用javascript函数以将窗口滚动到顶部。 I have one master page with a JS function "top" for scrolling page to the top, inside Master Page there is updatepanel and inside update panel there is iframe.Every time when iframe loads i want the masterpage to be on top. 我有一个具有JS函数“顶部”的母版页,用于将页面滚动到顶部,在母版页中有updatepanel,在更新面板中有iframe。每次加载iframe时,我都希望母版页位于顶部。

Solutions i have tried: 我尝试过的解决方案:

but i am getting compile time error tht onload cant be added to iframe becz it is inside an update panel 但是我遇到了编译时错误,无法将onload添加到iframe,因为它在更新面板中

i know my question is not very clear.still expecting some response. 我知道我的问题不是很清楚。仍然期望得到一些答复。

Assumption: both the iframe and parent window are from the same domain. 假设: iframe和父窗口均来自同一域。

You can do this to retrieve the reference to the iframe's parent DOM element: 您可以执行以下操作来检索对iframe父DOM元素的引用:

var iframeParent = window.parent.document;

With that reference, you can access the parent's functions that are in the global scope, so in your case the "top function" for scrolling the page? 使用该参考,您可以访问全局范围内父级的功能,因此在您的情况下,用于滚动页面的“顶级功能”?

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

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