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


  • 相关阅读:
    迭代器生成器
    eval()
    【剑指offer】调整数组数字位置
    【剑指offer】二进制中1的个数
    【剑指offer】斐波那契数列非递归求解第N项
    【剑指offer】两个栈实现队列
    【剑指offer】逆序输出链表
    【剑指offer】字符串替换
    【剑指offer】规则二维数组查找
    Java转型
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/14166716.html
Copyright © 2011-2022 走看看