[英]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.