我的问题是: 我有一些卡口与一个下拉菜单,每个标签都有一个iframe: 插入在跨域iframe中的内容头一个js
当用户点击下拉菜单,我需要运行在iframe中的内容有些JS,那么我认为,做正确的事情是这个js在我的html页面:
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
但是当我运行它,就像控制台报告:
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin " http://localhost:8080 " from accessing a frame with origin " http://www.otherdomainsite.com ". Protocols, domains, and ports must match.
显然,如果它位于不同的域上,它不会运行,那么我现在必须做什么?难道我做错了什么?
我听说过postMessage ecc ..方法,但我从来没有使用过它们。
预先感谢您。
有没有解决方案,或者真的不可能? – Asjon