如何从iframe刷新父窗口?

时间:2021-04-30 23:59:20

I've got a parent page and an iframe inside that page. The links in the parent control the page that gets loaded in the iframe. What I want to do is refresh the parent page when the iframe gets loaded. I've got this in the iframe:

我有一个父页面和一个iframe。父控件中的链接控制在iframe中加载的页面。我要做的是在加载iframe时刷新父页面。我在iframe中有这个:

RefreshParent(){
    parent.location.reload();
}

<body onload="RefreshParent();">

But, the above code refreshes the whole parent page along with the iframe inside it which in turn reloads the parent page and goes into an infinite loop.

但是,上面的代码刷新了整个父页面以及其中的iframe, iframe反过来重新加载父页面并进入无限循环。

6 个解决方案

#1


9  

You can't refresh the parent page without reloading the iframe.

如果没有重新加载iframe,就不能刷新父页面。

What you could do is use AJAX to update the parent's content, but that could be a fair amount of work (using the jQuery or Prototype frameworks would make this easier).

您可以使用AJAX更新父类的内容,但这可能是相当多的工作(使用jQuery或原型框架将使这更容易)。

#2


2  

You won't need to use ajax techniques either. You can simply call a javascript function in parent page from the page contained in the iframe of parent page. This way you can easily perform actions on parent page. How to refresh parent page partially from page in iframe without affecting the iframe illustrates how.

您也不需要使用ajax技术。只需从父页面的iframe中包含的页面调用父页面中的javascript函数。通过这种方式,您可以轻松地在父页面上执行操作。如何在不影响iframe的情况下在iframe中部分地从页面中刷新父页面。

Hope this helps.

希望这个有帮助。

#3


1  

You can't tell the parent window to refresh and exclude any part of its own page, including the iframe contained within it. You can do this using AJAX techniques though.

您不能告诉父窗口刷新并排除它自己页面的任何部分,包括其中包含的iframe。不过,您可以使用AJAX技术来实现这一点。

#4


1  

As long as your on the same domain you can use something like:

只要你在同一领域,你可以使用以下内容:

window.parent.location = window.parent.location + '?parent-updated=true'

#5


0  

You'll need to have your iframe become a "regular" frame in order to preserve it while refreshing another part of the page. Since the iframe is technically part of the parent (it's an inline frame, after all), refreshing the parent will reload the iframe content as well.

您需要使您的iframe成为“常规”框架,以便在刷新页面的另一部分时保存它。由于iframe在技术上是父框架的一部分(毕竟是内联框架),刷新父框架也将重新加载iframe内容。

#6


0  

Depends what your layout is, but as other posts have observed you cannot refresh the parent frame without refreshing the iframe itself as it is part of the page.

取决于布局是什么,但是正如其他文章所观察到的,如果不刷新iframe本身,就不能刷新父框架,因为它是页面的一部分。

If you do not wish to use ajax, and layout permits, one solution is to place the contents of the parent frame in an iframe itself. You can then tell the parent page to refresh the iframe containing the 'parent content' when your iframe loads. If your 'parent' iframe is borderless and there is no scrolling then this is all transparent to the user.

如果不希望使用ajax和布局许可,一种解决方案是将父框架的内容放在iframe本身中。然后,您可以告诉父页面在iframe加载时刷新包含“父内容”的iframe。如果您的“父”iframe是无边界的,并且没有滚动,那么这对用户来说都是透明的。

You could push this technique as far as a couple of iframes for the parent contents and it can be quicker and simpler to implement than ajax, beyond that you're as well to bite the bullet and implement an ajax solution.

您可以将这种技术扩展到父内容的两个iframe,并且它比ajax实现起来更快、更简单,除此之外,您还可以咬紧牙关实现ajax解决方案。

#1


9  

You can't refresh the parent page without reloading the iframe.

如果没有重新加载iframe,就不能刷新父页面。

What you could do is use AJAX to update the parent's content, but that could be a fair amount of work (using the jQuery or Prototype frameworks would make this easier).

您可以使用AJAX更新父类的内容,但这可能是相当多的工作(使用jQuery或原型框架将使这更容易)。

#2


2  

You won't need to use ajax techniques either. You can simply call a javascript function in parent page from the page contained in the iframe of parent page. This way you can easily perform actions on parent page. How to refresh parent page partially from page in iframe without affecting the iframe illustrates how.

您也不需要使用ajax技术。只需从父页面的iframe中包含的页面调用父页面中的javascript函数。通过这种方式,您可以轻松地在父页面上执行操作。如何在不影响iframe的情况下在iframe中部分地从页面中刷新父页面。

Hope this helps.

希望这个有帮助。

#3


1  

You can't tell the parent window to refresh and exclude any part of its own page, including the iframe contained within it. You can do this using AJAX techniques though.

您不能告诉父窗口刷新并排除它自己页面的任何部分,包括其中包含的iframe。不过,您可以使用AJAX技术来实现这一点。

#4


1  

As long as your on the same domain you can use something like:

只要你在同一领域,你可以使用以下内容:

window.parent.location = window.parent.location + '?parent-updated=true'

#5


0  

You'll need to have your iframe become a "regular" frame in order to preserve it while refreshing another part of the page. Since the iframe is technically part of the parent (it's an inline frame, after all), refreshing the parent will reload the iframe content as well.

您需要使您的iframe成为“常规”框架,以便在刷新页面的另一部分时保存它。由于iframe在技术上是父框架的一部分(毕竟是内联框架),刷新父框架也将重新加载iframe内容。

#6


0  

Depends what your layout is, but as other posts have observed you cannot refresh the parent frame without refreshing the iframe itself as it is part of the page.

取决于布局是什么,但是正如其他文章所观察到的,如果不刷新iframe本身,就不能刷新父框架,因为它是页面的一部分。

If you do not wish to use ajax, and layout permits, one solution is to place the contents of the parent frame in an iframe itself. You can then tell the parent page to refresh the iframe containing the 'parent content' when your iframe loads. If your 'parent' iframe is borderless and there is no scrolling then this is all transparent to the user.

如果不希望使用ajax和布局许可,一种解决方案是将父框架的内容放在iframe本身中。然后,您可以告诉父页面在iframe加载时刷新包含“父内容”的iframe。如果您的“父”iframe是无边界的,并且没有滚动,那么这对用户来说都是透明的。

You could push this technique as far as a couple of iframes for the parent contents and it can be quicker and simpler to implement than ajax, beyond that you're as well to bite the bullet and implement an ajax solution.

您可以将这种技术扩展到父内容的两个iframe,并且它比ajax实现起来更快、更简单,除此之外,您还可以咬紧牙关实现ajax解决方案。