开发者

Find Child in iFrame?

I am trying to achieve this:

I am working on a script that checks a Page for iFrames(done), but than it tries to find the VIDEO Tag of HTML5 in it, store its source, than remove the iframe and replace it by a new VIDEO Tag created with the prev开发者_StackOverflow社区iously retrieved source, the script shall grab the Element from cross domain Sites like YouTube e.g.

So currently I was able to find all iFrames via getElementB

and btw: JavaScript ONLY


It is impossible to do it cross domain because JavaScript has the same origin policy that prevents accessing the content from different domains.


As mentioned within another answer, this is not possible to do in a cross domain setup.

If this is not an issue, you can access the document of the iframe using the following:

var iframeElmnt = documentGetElementsByTagName('iframe')[0];
var iframeDocument = iframeElmnt.contentWindow.document;
var videoElmnts = iframeDocument.documentGetElementsByTagName('video');

You can then hunt through the videoElmnts to figure out which one you should insert into the current page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜