2

因为即使我查看 css 或 js 文件也会触发我的扩展的页面加载,我想添加另一个检查,仅当当前页面的内容类型为 text/html 时才会触发我的扩展。

//eg: at my page load handler
function onPageload(){

  // only want to proceed if content-type reflects a text/html or */html page
  if ( contentTypeIsHtml() ){
    //continue here
  }
}

contentTypeIsHtml() 应该做什么?

4

2 回答 2

4

您可以使用 document.contentType 属性获取内容类型(这不是标准 DOM,但可以被扩展使用)

于 2010-05-17T18:27:05.677 回答
1

查看附加组件 JSONView 的源代码,解压缩 xpi 并查看 components/jsonview.js,在源代码末尾,附加组件会为 mime 类型的 application/json 注册自身。你可能会做类似的事情。

于 2010-05-17T14:41:04.250 回答