为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

javascript where does id element +source exist

more options

In javascript I want to find the SOURCE code that created the element. I have a variable that might be created in one of several places. The web page is dynamically modified via ajax calls. During debug I want to ask the question "where did you originate"?

Is there a function like that? Can I create one easily? If not, would it be worthy of the Firefox team?

In javascript I want to find the SOURCE code that created the element. I have a variable that might be created in one of several places. The web page is dynamically modified via ajax calls. During debug I want to ask the question "where did you originate"? Is there a function like that? Can I create one easily? If not, would it be worthy of the Firefox team?

所有回复 (7)

more options
more options

Unfortunately, that information -- "how exactly did this element get added to the DOM" -- is not part of the DOM itself, so I can't think of any place to access it.

It would be interesting to try to create such a feature. If I were to inject a Mutation Observer into the document to take some action every time an element were added to the DOM, I don't know how my script could determine what line in what script just did that. Looking at it from the other perspective, could the debugger be persuaded to log the relevant details each time it added an element to the DOM? This probably exists in some debugger somewhere and probably could be brought to Firefox, but... not by me.

more options

You would probably need a full stack trace to be able to see what JavaScript code got executed and what parameters were used. This would involve a very large amount of data and thus would slow down Firefox in such a way that it wouldn't be usable.

more options

jscher2000,

How about an approach where the element(s) are identified in advance? In other words, I want to know the instance source of foobar so when the various sources are processed just id/name=foobar have supplemented code generated. At execution time the extra code reports on the origin source, perhaps in a user designated variable.

more options

It's not uncommon to set a watch in a debugger, but the details are beyond my expertise.

more options

The debugger would not meet my application needs since the program would be in production.

I suppose I'm just going to need to give up on this feature request for now.

I'll find a different way.

more options

I'm not sure you should give up just yet... This support forum is not a place to get features added to Firefox; at most we can describe what's available now, what we know to be coming, the add-ons we know about, and ideas we might have. You could take your request to either or both of the following: