[英]Cross domain iframe src changes
I have an application which contains an iframe.我有一个包含 iframe 的应用程序。 I can modify the contents of the iframe, but not the whole page itself, eg:我可以修改 iframe 的内容,但不能修改整个页面本身,例如:
<html><head></head>
<body>
<iframe>
<!-- my code -->
</iframe>
</body></html>
I have a requirement in which I need to change contents of the iframe to a different page (possibly on a different domain) and go back.我有一个要求,我需要将 iframe 的内容更改为不同的页面(可能在不同的域中)并返回。 Currently I do it like this: The first page (it is inside the iframe executionPanelApplications):目前我是这样做的:第一页(它在 iframe executionPanelApplications 内):
<html>
<head>
<script type="text/javascript">
function replaceIFrameUrl() {
var doSubmit = "<c:out value='${param.doSubmit}'/>";
if (doSubmit == 1) {
document.forms['testForm'].submit();
}
else {
var adfUrl = "<fuego:fieldValue att='instJs.adfUrl' onlyValue='true'/>";
var bpmSrc = parent.document.getElementById('executionPanelApplications').src;
var bpmSrcParams = bpmSrc.split('&');
var activityId = (bpmSrcParams[1].split('='))[1];
var url = adfUrl +"&actionType=0&activityId="+activityId;
parent.document.getElementById('executionPanelApplications').src = url;
}
};
</script>
</head>
<body onload="replaceIFrameUrl();">
<form method="post" id="testForm" name="testForm" />
</body>
</html>
The second page (it should be inside the iframe executionPanelApplications as well):第二页(它也应该在 iframe executionPanelApplications 内):
<script>
function leave(e) {
var iframe = parent.parent.document.getElementById("executionPanelApplications");
iframe.src = url;
};
</script>
If both sites are in localhost it works like a charm.如果两个站点都在 localhost 中,它就像一个魅力。 Unfortunatelly if they are in different domains - the second page is opened in a new window.不幸的是,如果它们在不同的域中 - 第二页将在新窗口中打开。 Tested in ie 8. As i said - i can't change the contents of the page that contains the iframe.在 ie 8 中进行了测试。正如我所说的 - 我无法更改包含 iframe 的页面的内容。 I can only work from inside the iframe.我只能在 iframe 内部工作。 I need this to work only in ie.我需要这个只在 ie 中工作。
Any ideas?有任何想法吗?
I would not use iframes, because there are different security restrictions (cross domain communication)我不会使用 iframe,因为有不同的安全限制(跨域通信)
But I think, this one can help you: http://softwareas.com/cross-domain-communication-with-iframes但我认为,这个可以帮助你: http : //softwareas.com/cross-domain-communication-with-iframes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.