javascript - access subdomain iframe url from other subdomain page -
i'm trying access iframe contentwindow property iframe hosted on subdomain within same domain. have code on a.domain.com (which hosts 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.com , want current page in iframe.
i see examples need set document.domain = "domain.com" in both a.domain.com , b.domain.com example need set in a.domain.com , b.domain.com regarding document.domain?
in pages in b.domain.com need set document.domain value?
thanks in advance, laziale
i in same situation , found using window.postmessage better way communicate between frames: https://developer.mozilla.org/en-us/docs/web/api/window.postmessage
if want use method mentioned, every page loads within frame need manually set document.domain on load. parent page need set it. built-in javascript property of document object.
Comments
Post a Comment