How are you setting up the onclick handler? If you are doing something like:
someElement.innerHTML = "<div onclick='foo()'>dfsd</div>"; ... that would explain what you are seeing. Content scripts do indeed run in a separate context from page script. When you use innerHTML you get the page JS. <script> tags are another way to get to the page JS. For more information, see: http://code.google.com/chrome/extensions/content_scripts.html#execution-environment - a On Tue, Nov 24, 2009 at 9:07 AM, Dominick D'Aniello <netpr...@gmail.com> wrote: > Hello, > > I am working on porting over an existing firefox extension to chrome. > So far it is going quite well. I am running into an issue with > retrieving variables stored on the document object. In my content > script I assign a variable on the document: > > document.foo = "bar" > > And then later, in a click event (on an element my content script > added, and bound click event to) if I try to retrieve the value, it > does not seem to be defined. If I redefine it in this click event, it > is defined in subsequent click calls. It seems that click event is > executing in a different context than the rest of my code (at least in > respect to the document object). However, If I store the variable > somewhere else, for example: > > MyExtension.foo = "bar" > > Then I can access it in both contexts, but as I mentioned I am porting > over an existing extension, and would like to keep the code as > consistent as possible. Additionally, if I console.log(document) in > both of these contexts, I get slightly different output. From the > click event I get a "Document" while the other context gives me an > "HTMLDocument"... They are both referring to the same doc (at least > document.title is the same for both). This further leads me to believe > the context is different somehow. > > Any ideas why I would be seeing this issue, and/or how I might get > around it and get a reference to the same document object in both > contexts? > > Thanks! > > - Dominick D'Aniello > > -- > > You received this message because you are subscribed to the Google Groups > "Chromium-extensions" group. > To post to this group, send email to chromium-extensi...@googlegroups.com. > To unsubscribe from this group, send email to > chromium-extensions+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/chromium-extensions?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Chromium-extensions" group. To post to this group, send email to chromium-extensi...@googlegroups.com. To unsubscribe from this group, send email to chromium-extensions+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/chromium-extensions?hl=en.