views:

105

answers:

2

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 ?

A: 

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.

Michael
ya had a look at it. thankfully, i dont have to build xpcom, or streams or interfaces. got to understand how mozilla internally figures out content types though. document.contentType works great. thanks michael.
bosky101
+2  A: 

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

fms
thanks, was going banana's trying to create an xpcom component, it's various interfaces and listened to every page ( not to forget scattered docs on xpcom over the years ). cheers!
bosky101