JS How to get cross-domain iframe inside content

Source: Internet
Author: User

Learn a little bit of programming every day PDF ebook, video tutorial free download:
Http://www.shitanlife.com/code

Where src may exist across domains.

Available methods of Access

var test = document.getElementsByClassName("iframeItem");var content =test[0].contentDocument||test[0].contentWindow.document;

But the error will be cross-domain:

a frame with origin "http://xxx.com" from accessing a cross-origin frame



跨域是无法解决的,如果有你有两个网站的权限的话,可以通过一些 hack 的方式绕过来通信。 
如 window.frames 属性(IE并不能全兼容)

这种情况一般涉及到跨域的话,都不去直接操作dom,都会想html5的on/postmessage一样。可以利用事件进行通讯。
可以参照这里有的https://github.com/YataoZhang/xMan 看frame方法。就是处理这种情况的。

Learn a little bit of programming every day PDF ebook, video tutorial free download:
Http://www.shitanlife.com/code

JS How to get cross-domain iframe inside content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.