BOM操作里面的:window、history、location

1.window

1.常用的提示框
window.alert(“弹框”);

if(window.confirm("确认是否提交?"))
     {
     console.log("确认");
     }
     else{
     console.log("用户拒绝");
     }

返回值为字符串 : var price = prompt("请输入价格:", '0');
2. window的事件

 window.onload = function () {
        console.log("加载完成");
    }

3.窗口大小变化事件

window.onresize = function () {
        //浏览器可视区域的尺寸
        console.log(window.innerWidth,window.innerHeight);
        //浏览器的大小
        console.log(window.outerWidth,window.outerHeight);
        //屏幕的实际尺寸
        console.log(window.screen.width);
        console.log(window.screen.height);
        //屏幕尺寸   不包含任务栏
        console.log(window.screen.availWidth);
        console.log(window.screen.availHeight);
        console.log(document.documentElement.clientWidth);
        console.log(window.screen.availWidth);
        console.log(window.innerWidth);
    }

4.禁止浏览器的右键菜单

 window.oncontextmenu = function (e) {
        //阻止事件默认行为
        e.preventDefault();
    }

5.加载失败

window.onerror=function (){
        console.log(1);
    }

6.navigator 对象 存在当前设备信息系统环境
可以使用下边这个代码检测 设备系统

console.log(window.navigator.userAgent);

7.浏览器上的复制事件 (给body添加)

 <style>
        .copy{
           opacity: 0;
        }
    </style>
    <script>
 document.body.oncopy = function (e) {
        //根据浏览器的兼容写代码
        //document.selection.createRange().text  这个是ie 识别
        var selection = window.getSelection() ? window.getSelection() : document.selection.createRange().text;
        var link = "<br/>******************************************************<br/>" + +
                        "转载来源:<br/>" +
                "原文地址:" + location.href +
                "<br/>******************************************************<br/>";
        var copytext = selection + link;
        if (window.clipboardData) {
            window.clipboardData.setData("Text", copytext);
        } else {
            //使用元素创建
            var div=document.createElement("div");
            div.className="copy";
            div.innerHTML=copytext;
            document.body.appendChild(div);
            selection.selectAllChildren(div);
            setTimeout(function (){
                div.remove();
            },0)
        }
    }
    </script>

2.history

  1. history.back();//后退
    history.forward();//前进
    history.go();//参数: 1 前进1 -1倒退1

3.location

1.地址栏对象
console.log(location);
console.log(location.host);//设置或返回当前 URL 的主机名称和端口号。
console.log(location.hostname);//设置或返回当前 URL 的主机名
console.log(location.origin);
console.log(location.pathname);//设置或返回当前 URL 的路径部分
console.log(location.port);//设置或返回当前 URL 的端口部分
2.重新加载: location.reload();
3.获取地址: console.log(location.href);
4.跳转页面
location.href=“https://www.baidu.com”;
location.replace(“https://www.baidu.com”);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值