How can firefox extension detect the content type of a page?

since my pageload extension fires even when I view the css or js files, I want to add another validation that only triggers my extension when the current page 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?

+2


a source to share


2 answers


You can get the content type using the document.contentType property (this is not the standard DOM, but must be used by extensions)



+4


a source


Check the source for the JSONView add-in, unzip the xpi and look at the /jsonview.js components, at the end of the source code, the add-in registers itself for the / json mime app. Perhaps you could do something like this.



+1


a source







All Articles