zoukankan      html  css  js  c++  java
  • ☀【document / location】

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <div id="box1">box1</div>
        <div id="box2">box2</div>
        <div id="box3">box3</div>
        <div id="box4">box4</div>
        <script>
            var url = 'http://static01.baomihua.com/js/lib/jquery-1.4.4.min.js'
            var doc = document
            var loc = location
            var box1 = doc.getElementById('box1')
            var box2 = doc.getElementById('box2')
            var box3 = doc.getElementById('box3')
            var box4 = doc.getElementById('box4')
    
            /*
             * window.location
             * 属性:
             * hash 设置或返回从井号 (#) 开始的 URL(锚)
             * host 设置或返回主机名和当前 URL 的端口号
             * hostname 设置或返回当前 URL 的主机名
             * href 设置或返回完整的 URL
             * pathname 设置或返回当前 URL 的路径部分
             * port 设置或返回当前 URL 的端口号
             * protocol 设置或返回当前 URL 的协议
             * search 设置或返回从问号 (?) 开始的 URL(查询部分)
             * 方法:
             * assign 加载新的文档
             * reload 重新加载当前文档
             * replace 用新的文档替换当前文档
             */
            // 加载新文档
            box1.onclick = function() {
                loc.href = url
            }
    
            box2.onclick = function() {
                loc.assign(url)
            }
    
            // 页面刷新
            box3.onclick = function() {
                loc.reload()
            }
    
            /*
             * window.document
             * 属性:
             * cookie 设置或返回与当前文档有关的所有 cookie
             * domain 返回当前文档的域名
             * referrer 返回载入当前文档的文档的 URL
             * title 返回当前文档的标题
             * URL 返回当前文档的 URL
             * 方法:
             * close
             * open
             * write
             * writeln
             * getElementById
             * getElementsByName
             * getElementsByTagName
             */
            // 返回载入当前文档的文档的URL
            console.log(doc.referrer)
            
            // 返回当前文档的URL
            console.log(doc.URL)
    
            // 返回当前文档的域名
            console.log(doc.domain)
    
            // 新窗口打开 用户点击不会被浏览器屏蔽
            box4.onclick = function() {
                open(url)
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    leetcode 86. Partition List
    leetcode 303. Range Sum Query
    leetcode 1310. XOR Queries of a Subarray
    leetcode 1309. Decrypt String from Alphabet to Integer Mapping
    leetcode 215. Kth Largest Element in an Array
    将numpy.ndarray写入excel
    leetcode 1021 Remove Outermost Parentheses
    leetcode 1306. Jump Game III
    leetcode 1305. All Elements in Two Binary Search Trees
    ICCV2019 oral:Wavelet Domain Style Transfer for an Effective Perception-distortion Tradeoff in Single Image Super-Resolution
  • 原文地址:https://www.cnblogs.com/jzm17173/p/3217250.html
Copyright © 2011-2022 走看看