码迷,mamicode.com
首页 > Windows程序 > 详细

捕获浏览器的前进、后退事件 window.onhashchange 并区别于点击链接

时间:2016-10-11 21:11:23      阅读:706      评论:0      收藏:0      [点我收藏+]

标签:

<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>

  

捕获浏览器的前进、后退事件 window.onhashchange 并区别于点击链接

标签:

原文地址:http://www.cnblogs.com/bushe/p/5950429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!