本系列文章旨在讲解如何从零开始搭建前端监控系统。html
项目已经开源前端
项目地址:git
您的支持是咱们不断前进的动力。github
喜欢请start!!!web
喜欢请start!!!api
喜欢请start!!!bash
本文是该系列第二篇,重点讲解如何实现圈选功能。post
若是你还不了解怎么捕获click事件,请先看第一篇ui
系列文章:spa
bombayjs.github.io/bombayjs/ex…
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<iframe id='iframe' src='./a.html'></iframe>
</div>
<script>
window.addEventListener('message', function(event) {
console.log(event.data.path)
}, false)
</script>
</body>
</html>
复制代码
// a.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<a href='#a'>click me</a>
</div>
<script>
window.addEventListener('message', function(event) {
console.log(event.data.path)
}, false)
window.addEventListener('click', function(event) {
event.stopPropagation()
window.parent.postMessage({
path: '此处须要本身解析出元素路径'
}, '*')
return
}, false)
window.addEventListener('mouseover', function(event) {
event.target.style = 'border: #ff0000 solid 1px'
}, false)
</script>
</body>
</html>
复制代码