PerformanceEntry.entryType - Web API 接口参考 编辑


  

The entryType  返回一个代表performance metric 类型的DOMString , 例如被performance.mark("begin") 所创建的entry 的entryType 就是 "mark". 此属性只读.

语法

var type = entry.entryType;

返回值

返回值取决于  PerformanceEntry 对象的subtype, entryType的取值会影响PerformanceEntry.name 属性, 具体如下表所示. 

Value Subtype Type of name property Description of name property
frame, navigation PerformanceFrameTiming, PerformanceNavigationTiming URL The document's address.
resource PerformanceResourceTiming URL The resolved URL of the requested resource. This value doesn't change even if the request is redirected.
mark PerformanceMark DOMString The name used when the mark was created by calling performance.mark().
measure PerformanceMeasure DOMString name used when the measure was created by calling performance.measure().
paint PerformancePaintTiming DOMString Either 'first-paint' or 'first-contentful-paint'.

 

范例

下面的代码说明了  entryType 属性的用法.

function run_PerformanceEntry() {

  // check for feature support before continuing
  if (performance.mark === undefined) {
    console.log("performance.mark not supported");
    return;
  }

  // Create a performance entry named "begin" via the mark() method
  performance.mark("begin");

  // Check the entryType of all the "begin" entries
  var entriesNamedBegin = performance.getEntriesByName("begin");
  //entriesNamedBegin
  //    Array [ PerformanceMark ]
  //entriesNamedBegin[0]
  //    PerformanceMark { name: "begin", entryType: "mark", startTime: 94661370.14, duration: 0 }
  //entriesNamedBegin[0].entryType
  //    "mark"
  //entriesNamedBegin[0].name
  //    "begin"

  for (var i=0; i < entriesNamedBegin.length; i++) {
      var typeOfEntry = entriesNamedBegin[i].entryType;
      console.log("Entry is type: " + typeOfEntry);
  }

}

Specifications

Specification Status Comment
Performance Timeline Level 2
entryType
Candidate Recommendation  
Performance Timeline
entryType
Recommendation Initial definition.

Browser compatibility

BCD tables only load in the browser

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:82 次

字数:5340

最后编辑:6 年前

编辑次数:0 次

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文