As shown in the picture, how to use js on page B to control page A to jump to a certain address?
If it is from the same source, just window.parent.location.href
can be used directly.
There is no solution if there are different sources and no control over the A page.
In the js of the B pagewindow.parent.window.location.href = '//www.baidu.com'
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
</head>
<body>
<iframe src="b.html"></iframe>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
function parentJump() {
window.parent.location.;
}
</script>
</head>
<body>
<button onclick="parentJump();">父頁(yè)面跳到百度</button>
</body>
</html>
Use window.parent
to access the parent form from a page in an iframe.