窗口性能不起作用

时间:2017-01-31 09:22:25

标签: javascript html

 var navigationStartTime                = window.performance.timing.navigationStart;

        function domTimingRecordEvents(){
            var domEventObject = {};
            var domArray = [];

            domEventObject.domLoadingStartTime            = (window.performance.timing.domLoading - navigationStartTime)/1000;
            domEventObject.domInteractiveTime             = (window.performance.timing.domInteractive - navigationStartTime)/1000;
            domEventObject.domContentLoadedEventStartTime = (window.performance.timing.domContentLoadedEventStart - navigationStartTime)/1000;
            domEventObject.domContentLoadedEventEndTime   = (window.performance.timing.domContentLoadedEventEnd - navigationStartTime)/1000;
            domEventObject.domCompleteTime                = (window.performance.timing.domComplete - navigationStartTime)/1000;
            domEventObject.loadEventStartTime             = (window.performance.timing.loadEventStart - navigationStartTime)/1000;
            //var loadEventEndTime               = (window.performance.timing.loadEventEnd - navigationStartTime)/1000;
            
            domArray.push(domEventObject);
            console.table(domArray);          
        }   

domTimingRecordEvents();

  1. 我上面的代码在chrome和firefox中顺利运行,但在Opera浏览器中运行时会出错。
  2. 我在opera窗口返回窗口中检查了控制台,但window.performance返回undefined
  3. 在上面的代码中,我在javascript中计算各种页面事件后,在几秒钟内得到时间。
  4. 我应该使用: -
  5.  var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
    

    并跳过上面的代码或有其他方法吗?

1 个答案:

答案 0 :(得分:1)

Windows性能它是JavaScript中的新功能,并且所有浏览器都不支持所有功能。

请查看Mozilla的此文档,了解为每个浏览器实现的功能

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