使用Jquery从iframe内部选择标记

时间:2015-07-13 20:17:08

标签: jquery html dom

我需要从嵌入式ifame中选择一个html5视频元素 (特别是嵌入youtube视频生成的视频元素)。 我知道我想使用$(" video")选择器来抓取元素,但因为它在iframe中它更复杂。

我发现.contents()方法会溢出iframe内容 (this link) 但是,请求被阻止,因为它是跨源请求。

这是我在尝试.contents()方法后得到的DOM错误:

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a cross-origin frame. at Error (native) at m.each.contents (file:///home/alex/Desktop/kiosk/Client/jquery.js:2:26679) at Function.m.extend.map (file:///home/alex/Desktop/kiosk/Client/jquery.js:2:3714) at m.each.m.fn.(anonymous function) [as contents] (file:///home/alex/Desktop/kiosk/Client/jquery.js:2:26777) at <anonymous>:2:9 at Object.InjectedScript._evaluateOn (<anonymous>:905:140) at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34) at Object.InjectedScript.evaluate (<anonymous>:694:21)

有任何想法可以修复或解决这个问题吗?

0 个答案:

没有答案