【发布时间】:2014-05-20 03:33:41
【问题描述】:
我正在尝试访问托管在同一域中的子域上的 iframe 的 iframe contentWindow 属性。所以我在 a.domain.com 上有这段代码(它承载了父页面的角色):
<script type="text/javascript">
$(document).ready(function () {
$('#frame').load(function () {
var iframe = document.getElementById('frame');
if (iframe) {
var item = iframe.contentWindow;
if (item.indexOf("Completed") != -1) {
window.location.href = '../Home/Completed/';
} else {
window.location.href = '../Home/PayAgain/';
}
}
});
});
</script>
实际的 iframe 内容位于 b.domain.com 上,我想在 iframe 中获取当前页面。
我看到一些示例,我需要在 a.domain.com 和 b.domain.com 中设置 document.domain = "domain.com" 但例如我需要在 a.domain.com 中设置什么和 b.domain.com 关于 document.domain?
我需要在 b.domain.com 的哪些页面设置 document.domain 的值?
【问题讨论】:
标签: javascript jquery html iframe same-origin-policy