Search code examples
javascriptfirefox-addoncontent-typexpcom

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 .

//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 ?


Solution

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