Skip to content

Commit bd8c461

Browse files
committed
also check iframes in inDoc (fix #2831)
1 parent e296646 commit bd8c461

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/util/dom.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@ export function query (el) {
3636
* @return {Boolean}
3737
*/
3838

39-
export function inDoc (node) {
40-
var doc = document.documentElement
39+
export function inDoc (node, win) {
40+
win = win || window
41+
var doc = win.document.documentElement
4142
var parent = node && node.parentNode
42-
return doc === node ||
43+
var isInDoc = doc === node ||
4344
doc === parent ||
4445
!!(parent && parent.nodeType === 1 && (doc.contains(parent)))
46+
if (!isInDoc) {
47+
var frames = win.frames
48+
if (frames) {
49+
for (var i = 0; i < frames.length; i++) {
50+
if (inDoc(node, frames[i])) {
51+
return true
52+
}
53+
}
54+
}
55+
}
56+
return isInDoc
4557
}
4658

4759
/**

test/unit/specs/util/dom_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ describe('Util - DOM', function () {
2222
expect(_.inDoc(target)).toBe(false)
2323
})
2424

25+
it('inDoc (iframe)', function (done) {
26+
var f = document.createElement('iframe')
27+
f.onload = function () {
28+
f.contentWindow.document.body.appendChild(target)
29+
expect(_.inDoc(target)).toBe(true)
30+
document.body.removeChild(f)
31+
done()
32+
}
33+
document.body.appendChild(f)
34+
f.src = "about:blank"
35+
})
36+
2537
it('getAttr', function () {
2638
target.setAttribute('v-test', 'ok')
2739
var val = _.getAttr(target, 'v-test')

0 commit comments

Comments
 (0)