X
點擊此處開啟此網站的行動版。

技術支援討論區

TypeError: Components.classes is undefined

已張貼

I saw many questions like "Components.classes[xyz]" is undefined, but I have an issue with the Components.classes object itself being undefined. I have a small dummy html page where I'm trying to run a basic sample script from http://books.mozdev.org/chapters/ch08.html#77008 (slightly altered):

<script type="text/javascript"> function blah() { var c = Components; var clazzes = c.classes; // clazzes is still undefined after this line executes var myClass = clazzes["@mozilla.org/browser/bookmarks-service;1"]; // here it throws var bmks = myClass.getService(Components.interfaces.nsIBookmarksService); // call one of the object's methods: // flush the bookmarks to disk if they've been touched. bmks.Flush( ); } </script>

I've already tried running Firefox in safe mode, and it's a fresh installation of the application. Am I missing some sort of initialization?

I saw many questions like "Components.classes[xyz]" is undefined, but I have an issue with the Components.classes object itself being undefined. I have a small dummy html page where I'm trying to run a basic sample script from http://books.mozdev.org/chapters/ch08.html#77008 (slightly altered): <html> <head> <script type="text/javascript"> function blah() { var c = Components; var clazzes = c.classes; // clazzes is still undefined after this line executes var myClass = clazzes["@mozilla.org/browser/bookmarks-service;1"]; // here it throws var bmks = myClass.getService(Components.interfaces.nsIBookmarksService); // call one of the object's methods: // flush the bookmarks to disk if they've been touched. bmks.Flush( ); } </script> </head> <body> </body> </html> I've already tried running Firefox in safe mode, and it's a fresh installation of the application. Am I missing some sort of initialization?

額外的系統細節

已安裝的外掛程式

  • The QuickTime Plugin allows you to view a wide variety of multimedia content in web pages. For more information, visit the QuickTime Web site.
  • Shockwave Flash 11.4 r402
  • Displays Java applet content, or a placeholder if Java is not installed.

應用程式

  • User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:15.0) Gecko/20100101 Firefox/15.0.1

更多資訊

jscher2000
  • Top 10 Contributor
8839 個解決方法 72250 個答案

Generally speaking, web pages cannot access the privileged parts of Firefox such as preferences and bookmarks. There is an exception for digitally signed scripts in some cases, but during development and testing, of course, that's impractical due to frequent code changes.

If you are working on creating an add-on, consider using the Add-on SDK. More info: https://addons.mozilla.org/developers/

Generally speaking, web pages cannot access the privileged parts of Firefox such as preferences and bookmarks. There is an exception for digitally signed scripts in some cases, but during development and testing, of course, that's impractical due to frequent code changes. If you are working on creating an add-on, consider using the Add-on SDK. More info: https://addons.mozilla.org/developers/