iframe包裹了a页面,页面监听click事件。a页面里a标签跳转到b页面,click事件就不会触发了。有什么办法能在iframe页面解决吗?a、b页面是动态生成的页面
iframe页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
iframe{
width: 800px;
height: 600px;
}
</style>
<body>
<div id="root">
<iframe src="./a.html" frameborder="0"></iframe>
</div>
<script>
window.onload=function(){
console.log(document.querySelector("iframe"));
document.querySelector("iframe").contentWindow.addEventListener('click',(e) => {
console.log('按下',e)
})
}
</script>
</body>
</html>
a页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>a页面</div>
<a href="./b.html">到b去</a>
</body>
</html>
b页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>b页面</div>
<a href="./a.html">到a去</a>
</body>
</html>