zoukankan      html  css  js  c++  java
  • 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 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    day08作业
    day07作业
    day06作业
    day05作业
    OOAD与UML
    大数据(3):基于sogou.500w.utf8数据Hbase和Spark实践
    大数据(2):基于sogou.500w.utf8数据hive的实践
    大数据(1):基于sogou.500w.utf8数据的MapReduce程序设计
    九大排序算法的Java实现
    数字在排序数组中出现的次数
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/14166716.html
Copyright © 2011-2022 走看看