Implementation idea and code of controlling parent page refresh by iframe in HTML

Time:2021-1-9

1、 Application scenarios

Parent page a.jsp
Sub page b.jsp, as the page pointed by the iframe embedded in page a

Copy code

The code is as follows:

<body>
<iframe src=”b.jsp” …/>
</body>

Now we do an operation in the B page. After the operation, we need to refresh the iframe embedded in the a page

2、 Ideas

Find page a in page B, then find the iframe in page a, and assign the SRC attribute of the iframe again.

3、 Implementation

In b.jsp

Copy code

The code is as follows:

function refresh(){
var frame = window.parent.document.getElementById(“frame”);
var path = frame.getAttribute(“src”);
frame.setAttribute(“src”, path);
}

This only refreshes the frame and the effect of local refresh.