标签:chrome screen get 页面 div firefox replace 是你 rip
1 console.log(window); 2 console.log(navigator); 3 console.log(location); 4 console.log(history); 5 console.log(screen);
1 var userAgent = navigator.userAgent; 2 console.log(userAgent); 3 4 if(/firefox/i.test(userAgent)){ 5 alert("我是一只可爱的狐狸!"); 6 }else if(/chrome/i.test(userAgent)){ 7 alert("我是你哥, 我叫谷歌!"); 8 }else if(/msie/i.test(userAgent)){ 9 alert("我是IE, 不服来打我呀!"); 10 }else if("ActiveXObject" in window){ 11 alert("IE11, 爱用不用!"); 12 }
1 var btn = document.getElementById(‘btn‘); 2 btn.addEventListener(‘click‘, function (ev) { 3 console.log(history); 4 // history.back();//回退到上一个页面 5 // history.forward();//跳转到下一个页面 6 // history.go(1);//向前跳转一个页面 7 // history.go(-1);//向后跳转一个页面 8 });
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <button id="btn">点我</button> 9 <a href="http://www.itlike.com">官网</a> 10 <script> 11 var btn = document.getElementById(‘btn‘); 12 btn.addEventListener(‘click‘, function (ev) { 13 console.log(location); 14 // console.log(location.toString()); 15 // location = "http://www.itlike.com"; 16 // location.assign(‘http://www.itlike.com‘);//跳转 17 // location.reload();//刷新 18 // location.replace(‘http://www.baidu.com‘);//替换当前页面 19 location.href = ‘http://www.itlike.com‘;//跳转 20 }); 21 </script> 22 </body> 23 </html>
标签:chrome screen get 页面 div firefox replace 是你 rip
原文地址:https://www.cnblogs.com/zhangzhengyang/p/11241218.html