[英]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
按顺序为后续页面加载生命周期事件提供时间戳:
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.