捕獲瀏覽器的前進、后退事件 window.onhashchange 並區別於點擊鏈接


<html>   
    
    <head>   
        <meta http-equiv="content-type" content="text/html;charset=utf-8">   
        <title>onhashchange測試</title></head>   
    
    <body>
            <a href="#p2">p2</a>
    <script>
       document.onmouseover = function() {
            //User's mouse is inside the page.
            window.innerDocClick = true;
        }

        document.onmouseleave = function() {
            //User's mouse has left the page.
            window.innerDocClick = false;
        }

        window.onhashchange = function() {
            if (window.innerDocClick) {
                //Your own in-page mechanism triggered the hash change
                alert('You click a link');
            } else {
                //Browser back button was clicked
                alert('You click browser button');
            }
        }   </script>   
</html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM