#8818 closed enhancement (patchwelcome)
.contains(window, document) throws an exception
Reported by: | TiTi | Owned by: | TiTi |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | selector | Version: | 1.5.2 |
Keywords: | needsreview | Cc: | |
Blocked by: | Blocking: |
Description
Hi,
I've notice the following command :
jQuery.contains(window, document);
throws a TypeError: a.compareDocumentPosition is not a function
Of course window is not a DOM node, so arguments are not correct, thus there is currently nothing wrong with .contains()
But I think it could be useful to check if a document is inside a particular window. This is why I'm submitting this as an enhancement.
Thx!
Change History (5)
comment:1 Changed 12 years ago by
Owner: | set to TiTi |
---|---|
Status: | new → pending |
comment:2 Changed 12 years ago by
Status: | pending → new |
---|
Hum, looks like this is a FireFox 4 issue ? It works in Opera 11, IE9, Chrome 10 (no alert).
comment:3 Changed 12 years ago by
Component: | unfiled → selector |
---|---|
Priority: | undecided → low |
Resolution: | → patchwelcome |
Status: | new → closed |
Thanks for replying back with a test case. Further information on compareDocumentPosition (which is used for one of the tests performed by .contains()) can be found here: https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition.
Also, the documentation for jQuery.contains() says:
jQuery.contains( container, contained )
container The DOM element that may contain the other element.
contained The DOM node that may be contained by the other element.
As you correctly point out, window is not a DOM node and so an exception here would be raised.
As for this coming in as an enhancement, I'm having a hard time trying to visualize a real-world scenario where needing to test that a document belongs to a particular window would be needed (to the extent that a lot of people would use this feature if included in core).
I believe this is an enhancement that *should* be possible to turn into a plugin outside of core itself. I'd recommend trying to do this and seeing just how well it's received or widely it's used. If you can prove demand, we'd certainly be open to considering it.
comment:4 Changed 12 years ago by
This is somewhat related to tickets #8010 and #4348: iframes usage.
Small demo with a single iframe: http://jsbin.com/esane5 You could imagine the same with popups [window.open()];
Anyways I submitted this idea because I found it weird that .contains() works with all nodes but not at top level (window/document). Turns out it fails only in firefox...
As my latest demo shows, you might wan't to use it if you manage several iframes / window. Indeed I don't think this will interest a lot of people, but I can't determine how much people would use this feature...
comment:5 Changed 12 years ago by
Keywords: | needsreview added |
---|
Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket! This will also assist in help build a case for this being considered as an enhancement, should we experience the same behaviour.
Additionally, test against the
jQuery (edge)
version to ensure the issue still exists.