简体   繁体   English

firefox扩展如何检测加载的页面的内容类型?

[英]how can a firefox extension detect content-type of the page loaded?

since my extension's pageload is triggered even when I view css or js files, i want to add another check that triggers my extension only when the current page's content-type is text/html . 由于即使在查看css或js文件时也会触发扩展程序的页面加载,因此我想添加另一条仅在当前页面的content-type为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
  }
}

what should contentTypeIsHtml() do ? contentTypeIsHtml()应该做什么?

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

Check out the source to the add-on JSONView, unzip the xpi and take a look at components/jsonview.js, towards the end of the source the add-on registers itself for the mime-type application/json. 签出附加组件JSONView的源代码,解压缩xpi并查看components / jsonview.js,在源代码的结尾处,附加组件将自己注册为mime类型的application / json。 You could probably do something similar. 您可能会做类似的事情。

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

相关问题 PHP:如何提供正确的内容类型(取决于文件扩展名?)? - PHP: how to serve right content-type (depending on file extension?)? Chrome扩展程序-在onBeforeRequest中获取Content-Type - Chrome extension - getting Content-Type in onBeforeRequest Chrome扩展程序:如何检测内容脚本是否已加载到选项卡中? - Chrome Extension: how to detect that content script is already loaded into a tab? 如何设置 XDomainRequest 对象的内容类型? - How can I set the content-type of XDomainRequest object? Firefox扩展开发:如何在内容脚本中创建全局函数,以便其他加载的脚本文件可以访问它? - Firefox extension development: How do I create a global function inside a content script, so other loaded script files can access it? Firefox 扩展:在页面加载时运行 - Firefox extension: run when page loaded 如何在firefox扩展中检测到成功登录? - How can I detect a successful login in my firefox extension? Firefox没有为多部分请求设置正确的内容类型 - Firefox not setting the right content-type for multipart request 与Chrome和Firefox POST通话的内容类型不同 - Content-Type difference with Chrome and Firefox POST call 当用户使用搜索栏搜索时,Firefox扩展程序如何检测? - How can a Firefox extension detect when user searches with search bar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM