2016년 12월 31일 토요일

location


https://www.blogger.com:8080/blogger.g?blogID=7210508282801009154#editor/target=post;postID=6236407181686720774

----------------------------------
location プロパティ
----------------------------------
window.location.href
window.location.host
window.location.hostname.
window.location.protocol
window.location.port
window.location.pathname
window.location.hash
window.location.search
window.location.username
window.location.password
window.location.origin
---------------------------------
location メソッド
---------------------------------
window.location.reload()
window.location.assign()
window.location.replace()
window.location.toString()
--------------------------------





window.location.href urlのすべて
window.location.host www.blogger.com:8080
window.location.pathname /logger.g
window.location.protocol   https
window.location.hostName www.blogger.com
window.location.port 8080
window.location.hash  #以降すべて
window.location.search ?blogId=72....  ~ #以前まで
window.location.origin  https:www.blogger.com

window.location.reload() 現在のページを再ロード (F5押したときと同様)
window.location.toString()  urlを表示
window.location.assign()  指定urlをロード
window.location.replace() 現在のurlの履歴を削除し、指定urlロード


-----------------------------------------------------------------------------
 http://localhost:8383/HTML5/location.html?userId=1234#gamenId='0303'

locationプロパティ
 


locationメソッド 


        <div id="locationName">
            http://localhost:8383/HTML5/location.html?userId=1234#gamenId='0303'
        </div>
        <div id="result" ></div>
        <div>locationプロパティ
            <button id="location">location</button>
            <button >href</button>
            <button >host</button>
            <button >protocol</button>
            <button >hostname</button>
            <button >pathname</button>
            <button >search</button>
            <button >hash</button>
            <button >username</button>
            <button >password</button>
            <button >origin</button>
        </div>
        <div>locationメソッド
            <button>reload()</button>
           <button>assign()</button>
           <button>replace()</button>
          <button>toString()</button>
        </div>
        <script>
            (function () {
                var buttonTags = $({tagName: 'BUTTON'});

                for (var idx = 0; idx < buttonTags.length; idx++) {
                    var el = buttonTags[idx];
                    el.id = el.innerHTML;
                    buttonTags[idx].addEventListener('click', getProp);
                }

                function getProp() {
                    debugger;
                    var id = event.target.id;
                    if (id === 'location') {
                        window.location = $({id: 'locationName'}).innerHTML;
                        return;
                    }
                   
                    // 指定urlロード
                    if(id === 'assign()'){
                        id = 'assign("http://www.google.co.jp/")';
                    }
                   
                    // 現在の履歴削除して、指定urlロード
                    if(id === 'replace()'){
                        id = 'replace("http://www.yahoo.co.jp/")';
                    }                  
                    var func = "window.location." + id;
                    var result = eval(func);
                    $({id: 'result'}).innerHTML = result;
                }

                function $(obj) {
                    debugger;
                    if (obj['id']) {
                        return document.getElementById(obj['id']);
                    }
                    if (obj['tagName']) {
                        return document.getElementsByTagName(obj['tagName']);
                    }
                }
            })();

        </script>










댓글 없음:

댓글 쓰기