how can a firefox extension detect content-type of the page loaded?
since my extension's pageload is triggered 开发者_StackOverflow中文版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 .
//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 ?
You can get the content type using the document.contentType property (this is not standard DOM, but is there to be used by extensions)
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. You could probably do something similar.
精彩评论