window对应的error没有event对象 window对应的error他接收三个参数,msg,url,行号
return false
return true
1就不会返回错误
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><script>// window.addEventListener("error",funtion(msg,url,line){window.onerror=function(msg,url,line){console.log(msg);console.log("=========");console.log(url);console.log("=========");console.log(line);return false;// return true;// 或者return一个true异步给服务器,这样用户就看不到错误信息了};let div=document.getElementById("div#out");div.innerHTML="Hello World";</script></body>
</html>
看到我们的错误类型
2error只能在try,catch这里面用
就可以写到客户端那边
3. 只要在我们的这个浏览器不同页面都共用同一个window
<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><a href="b.html">链接到b</a><input type="button" value="print"><script>window.name = "zhangsan";let btn = document.querySelector("input");btn.addEventListener("click", (event) => {alert(window.name);window.name = "lisi";})</script></body> </html>
<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><a href="a.html">链接到a</a><input type="button" value="print"><script>let btn=document.querySelector("input");btn.addEventListener("click",(event)=>{alert(window.name);})</script></body> </html>
嘿嘿我打印JSON字符串,JSON.stringify(data)
<body><a href="b.html">链接到b</a><input type="button" value="print"><script>let data={name:"zhangsan",age:18,gender:"female"}window.name = JSON.stringify(data);let btn = document.querySelector("input");btn.addEventListener("click", (event) => {alert(window.name);window.name = "lisi";})</script></body>
当然JSON.parse(window.name)可以转为JS对象