刷新父窗口上的子窗口

时间:2022-09-07 00:26:16

how can i refresh child page if parent window reloads?

如果父窗口重新加载,我该如何刷新子页面?

Suppose A.html has a link that opens B.html. B.html will automatically refresh if A.html reloads.

假设A.html有一个打开B.html的链接。如果A.html重新加载,B.html将自动刷新。

Any javascript/jQuery way?

任何javascript / jQuery方式?

1 个解决方案

#1


1  

You can control the child if you open it like this: (in A.html)

如果您打开它,您可以控制孩子:(在A.html中)

baby = window.open('B.html');

Refreshing the child will then be done like this:

刷新孩子将这样做:

baby.history.go(0);

If you refresh A, the pages unload-event will be invoked. So to refresh B when one refreshes (or leaves or closes, for that matter) A, you can do: (in A.html)

如果刷新A,将调用页面unload-event。因此,当一个刷新(或离开或关闭,就此而言)A时刷新B,你可以这样做:(在A.html中)

<body onunload="baby.history.go(0);">

But, after the refresh all javascript variables will be lost! It will lose its connection with page B! So it will only work for one time.

但是,刷新后所有的javascript变量都会丢失!它将失去与B页的连接!所以它只会工作一次。

I think a solution will be to make a refresh button/link in A.html, that will refresh the data on the page (A) dynamically in order to maintain the connection to the child windows (B).

我认为解决方案是在A.html中创建一个刷新按钮/链接,它将动态刷新页面(A)上的数据,以保持与子窗口(B)的连接。

#1


1  

You can control the child if you open it like this: (in A.html)

如果您打开它,您可以控制孩子:(在A.html中)

baby = window.open('B.html');

Refreshing the child will then be done like this:

刷新孩子将这样做:

baby.history.go(0);

If you refresh A, the pages unload-event will be invoked. So to refresh B when one refreshes (or leaves or closes, for that matter) A, you can do: (in A.html)

如果刷新A,将调用页面unload-event。因此,当一个刷新(或离开或关闭,就此而言)A时刷新B,你可以这样做:(在A.html中)

<body onunload="baby.history.go(0);">

But, after the refresh all javascript variables will be lost! It will lose its connection with page B! So it will only work for one time.

但是,刷新后所有的javascript变量都会丢失!它将失去与B页的连接!所以它只会工作一次。

I think a solution will be to make a refresh button/link in A.html, that will refresh the data on the page (A) dynamically in order to maintain the connection to the child windows (B).

我认为解决方案是在A.html中创建一个刷新按钮/链接,它将动态刷新页面(A)上的数据,以保持与子窗口(B)的连接。