[英]Insert a js on head of cross-domain iframe content
我的问题是:我有一些带有下拉菜单的标签,每个标签都有一个iframe:
当用户单击下拉菜单时,我需要在iframe内容上运行一些js,然后我认为正确的做法是在html页面中使用此js:
var scriptTag = "<script>alert("blabla");<"; // saving script to run
scriptTag += "/script>"; //add this for fixing the script tag problem
$("#myframeid").contents().find("head").append(scriptTag); //appending the script on the head of iframe
但是当我运行它时,控制台报告如下:
未捕获的SecurityError:无法从“ HTMLIFrameElement”读取“ contentDocument”属性:阻止了源为“ http:// localhost:8080 ”的框架访问源为“ http://www.otherdomainsite.com ”的框架。 协议,域和端口必须匹配。
显然,如果它在其他域中无法运行,那么我现在该怎么办? 难道我做错了什么?
我听说过postMessage ecc ..方法,但从未使用过。
先感谢您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.