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 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    HDU1172 猜数字 广搜
    HDU2688 Rotate
    HDU1006 Tick and Tick 几何
    ADO.NET中的五个主要对象
    .NET开发人员值得关注的七个开源项目
    常用正则表达式
    常用的正则表达式集锦〔转〕
    一个较优雅的GridView隐藏列取值解决方案
    DataTable分组求和
    处理[未处理的“System.StackOverflowException”类型的异常出现在 System.Windows.Fo ...
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/14166716.html
Copyright © 2011-2022 走看看