• xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!


    前端监控: 用户页面停留时间计算

    hashchange

    // event handler
    function locationHashChanged() {
      if (location.hash === '#cool-feature') {
        console.log("You're visiting a cool feature!");
      }
    }
    
    window.onhashchange = locationHashChanged;
    
    // event listener
    function hashListener() {
      console.log('The hash has changed!');
    }
    
    window.addEventListener('hashchange', hashListener, false);
    
    ```js
    // test, 覆盖 hash
    function changeHash() {
      location.hash = (Math.random() > 0.5) ? 'location1' : 'location2';
    }
    
    
    // Let this snippet run before your hashchange event binding code
    if (!window.HashChangeEvent)(function(){
      var lastURL = document.URL;
      window.addEventListener("hashchange", function(event){
        Object.defineProperty(event, "oldURL", {enumerable:true,configurable:true,value:lastURL});
        Object.defineProperty(event, "newURL", {enumerable:true,configurable:true,value:document.URL});
        lastURL = document.URL;
      });
    }());
    
    

    test

    
    hashchange = HashChangeEvent {isTrusted: true, oldURL: "http://localhost:8080/about?hash=%2Fabout%23abc#123", newURL: "http://localhost:8080/about?hash=%2Fabout%23abc#666", type: "hashchange", target: Window, …}bubbles: falsecancelBubble: falsecancelable: falsecomposed: falsecurrentTarget: Window {window: Window, self: Window, document: document, name: "", location: Location, …}defaultPrevented: falseeventPhase: 0isTrusted: truenewURL: "http://localhost:8080/about?hash=%2Fabout%23abc#666"oldURL: "http://localhost:8080/about?hash=%2Fabout%23abc#123"path: [Window]returnValue: truesrcElement: Window {window: Window, self: Window, document: document, name: "", location: Location, …}target: Window {window: Window, self: Window, document: document, name: "", location: Location, …}timeStamp: 310272.22499999334type: "hashchange"__proto__: HashChangeEvent
    
    

    refs

    https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onhashchange



    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    UIButton图文上下对齐
    安装cocoapods
    mac忘记密码的解决办法
    css3圆角边框,边框阴影
    input元素的padding border margin的区别
    css font-family 字体全介绍,5b8b4f53 宋体 随笔
    mysql数据库 thinkphp连贯操作where条件的判断不正确的问题
    php获取客户端ip get_client_ip()
    php session小节
    ajax返回值中有回车换行、空格解决方法
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/14166716.html
Copyright © 2020-2023  润新知