admin管理员组文章数量:1417421
I'm trying to access the iframe contentWindow property for an iframe which is hosted on a subdomain within the same domain. So I have this code on a.domain (which hosts the role of parent page):
<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>
The actual iframe content sits on b.domain and I want to get the current page in the iframe.
I see some examples that I need to set document.domain = "domain" in both a.domain and b.domain but for example what exactly do I need to set in a.domain and b.domain regarding document.domain?
In which pages in b.domain I need to set the document.domain value?
I'm trying to access the iframe contentWindow property for an iframe which is hosted on a subdomain within the same domain. So I have this code on a.domain. (which hosts the role of parent page):
<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>
The actual iframe content sits on b.domain. and I want to get the current page in the iframe.
I see some examples that I need to set document.domain = "domain." in both a.domain. and b.domain. but for example what exactly do I need to set in a.domain. and b.domain. regarding document.domain?
In which pages in b.domain. I need to set the document.domain value?
Share Improve this question edited Oct 30, 2021 at 22:18 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Apr 7, 2014 at 18:18 LazialeLaziale 8,24548 gold badges155 silver badges271 bronze badges2 Answers
Reset to default 3I was in this same situation and I found that using window.postMessage was a much better way to municate between the frames: https://developer.mozilla/en-US/docs/Web/API/Window.postMessage
If you want to use the method you mentioned, every page that loads within the frame will need to manually set document.domain on load. The parent page will also need to set it. It is just a built-in javascript property of the document object.
add document.domain = 'your.domain' in both the pages.
like this. don't forget both parent.top
document.domain = 'corp.local'; only parent like
document.domain = 'corp'; won't work.
As I've mentioned here. javascript get iframe url's current page on subdomain
this document helped. http://javascript.info/tutorial/same-origin-security-policy
本文标签: javascriptAccess subdomain iframe url from other subdomain pageStack Overflow
版权声明:本文标题:javascript - Access subdomain iframe url from other subdomain page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745263697a2650473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论