简体   繁体   English

我多久以前加载一个页面?

[英]How long ago did I load a page?

Is there a way to get how long ago a page was loaded using javascript, without having first recorded the time to a javascript variable on page load? 有没有办法让你在很久以前使用javascript加载页面,而没有首先在页面加载时记录javascript变量的时间? I'm hoping to create a scriptlet (javascript bookmark) that I can run on any web page and have it output how much time has passed since the browser loaded the page. 我希望创建一个可以在任何网页上运行的scriptlet(javascript书签),并让它输出自浏览器加载页面以来已经过了多少时间。

All of the "time spent on a page" solutions I've found so far rely on recording the time when the page first loads, which requires either access to modify a site, or a browser plugin. 到目前为止,我发现的所有“在页面上花费的时间”解决方案都依赖于记录页面首次加载的时间,这需要访问修改站点或浏览器插件。 Is there no document property that stores when the page was loaded (started, finished, etc.) which can be accessed in javascript? 是否存在可以在javascript中访问的页面加载(启动,完成等)时存储的文档属性?

You could use window.performance.timing.loadEventEnd : 你可以使用window.performance.timing.loadEventEnd

> performance.timing.loadEventEnd
1424280020354

window.performance.timing provides timestamps for the following page load lifecycle events, in order: window.performance.timing按顺序为后续页面加载生命周期事件提供时间戳:

  • navigationStart navigationStart
  • unloadEventStart unloadEventStart
  • unloadEventEnd unloadEventEnd
  • redirectStart redirectStart
  • redirectEnd redirectEnd
  • fetchStart fetchStart
  • domainLookupStart domainLookupStart
  • domainLookupEnd domainLookupEnd
  • connectStart connectStart
  • connectEnd connectEnd
  • secureConnectionStart secureConnectionStart
  • requestStart requestStart
  • responseStart responseStart
  • responseEnd responseEnd
  • domLoading domLoading
  • domInteractive domInteractive
  • domContentLoadedEventStart domContentLoadedEventStart
  • domContentLoadedEventEnd domContentLoadedEventEnd
  • domComplete domComplete
  • loadEventStart loadEventStart
  • loadEventEnd loadEventEnd

Source: Navigation Timing API on MDN 来源: MDN上的导航时序API

The Navigation Timing API is currently supported by most modern browsers. 大多数现代浏览器目前都支持Navigation Timing API。 Exceptions: Safari < 8 on OSX, Safari on iOS and Opera Mini. 例外:OSX上的Safari <8,iOS上的Safari和Opera Mini。 - caniuse.com . - caniuse.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示多久前用 JavaScript 发布的帖子 - Showing how long ago a post was made in JavaScript 多久以前给定的时间与现在相比较 - how long ago the given time was compared to now javascript Date Object多久以前 - javascript Date Object how long ago 页面加载或响应需要多长时间? - How long does it take the page to load or response? 页面首次加载,选项未更新,如何解决? - Page first load, options did not update, how to solve? 如何使用 moment.js 将日期时间字符串转换为一分钟前/一天前/一个月前/一年前格式 - How do I convert a datetime string to a mins ago/day ago/month ago/ year ago format using moment.js 记录未调用的“加载”事件回调; 我怎么搞砸了? - Document 'load' event callbacks not called; how did I mess this up? 如何在Algolia中创建相对日期/时间过滤器(即“一天前”,“两天前”,“三天前”)? - How can i create relative-date/time filter in Algolia (i.e. “a day ago”, “2 days ago”, “3 days ago”)? 如何使用客户端浏览器滚动加载HTML内容,就像在Facebook主页中一样? - how to use client browser scrolling to load the html contents as did in facebook home page? 他们如何隐藏此页面上的JavaScript? - How did they hide the JavaScript on this page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM