代码结构如下,具体的已省略
要在home.html为iframe添加onclick和onmousemove事件,而不是在main.html(因为iframe的src会根据侧边栏而改变)
拜托各位大神帮忙,谢谢~~
试试
document.querySelector('iframe').onload = function() {
var iframeWindow = document.querySelector('iframe').contentWindow
iframeWindow.document.body.onclick = function() {
console.log(1);
}
iframeWindow.document.body.onmousemove = function() {
console.log(2);
}
}