webNavigation.onDOMContentLoaded
在页面中触发DOMContentLoaded 事件时触发。此时,文档被加载和解析,并且 DOM 被完全构造,但链接的资源(例如图像,样式表和子框架(subframes))可能尚未被加载。
Syntax
js
browser.webNavigation.onDOMContentLoaded.addListener(
  listener,                   // function
  filter                      // optional object
)
browser.webNavigation.onDOMContentLoaded.removeListener(listener)
browser.webNavigation.onDOMContentLoaded.hasListener(listener)
事件有三个方法:
addListener(callback)- 
    
为此事件添加监听方法。
 removeListener(listener)- 
    
停止监听此事件。
listener参数为需要移出的监听方法。 hasListener(listener)- 
    
检测是否有
listener被注册在事件上。如果有返回true, 否则返回false. 
addListener syntax
参数
callback- 
    
为当此事件发生是需要被调用的函数。该函数将传递以下参数:
details- 
        
object. 有关导航(navigation)事件的详细信息。 
 filter可选- 
    
object. 包含单个属性url的对象,这是一个events.UrlFilter(en-US) 数组对象。如果包含此参数,则该事件将仅触发转换为与数组中至少一个UrlFilter匹配的 URL。在数组中。如果您省略此参数,则该事件将触发所有转换。 
Additional objects
details
tabId- 
    
integer. The ID of the tab in which the navigation has occurred. url- 
    
string. The URL to which the given frame has navigated. processId- 
    
integer. The ID of the process in which this tab is being rendered. frameId- 
    
integer. Frame in which the navigation is occurring. 0 indicates that navigation happens in the tab's top-level browsing context, not in a nested iframe. A positive value indicates that navigation happens in a nested iframe. Frame IDs are unique for a given tab and process. timeStamp- 
    
number. The time at whichDOMContentLoadedwas fired, in milliseconds since the epoch. 
Browser compatibility
BCD tables only load in the browser
Examples
Logs the target URLs for onDOMContentLoaded, if the target URL's hostname contains "example.com" or starts with "developer".
js
var filter = {
  url:
  [
    {hostContains: "example.com"},
    {hostPrefix: "developer"}
  ]
}
function logOnDOMContentLoaded(details) {
  console.log("onDOMContentLoaded: " + details.url);
}
browser.webNavigation.onDOMContentLoaded.addListener(logOnDOMContentLoaded, filter);
备注: This API is based on Chromium's chrome.webNavigation API. This documentation is derived from web_navigation.json in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.