Reputation: 569
I have an iframe inside a main page. The iframe is from the same exact domain as the main page.
main page url - https://example.edu:4450/... iframe url - https://example.edu:4450/...
But I'm still getting the cross origin frame error while clicking on some buttons that are executing some javascript code inside the iframe page. Why is this happening even though both urls are in the same domain? Is there a way to find out the exact cross-domain url that is causing this error? The alert message doesn't show the cross-domain url that is causing this error.
Upvotes: 1
Views: 4513
Reputation: 569
The JavaScript console showed the reason for the error.
Uncaught SecurityError: Blocked a frame with origin "https://dev.nss.xxx.edu:4450" from accessing a frame with origin "https://dev.nss.xxx.edu:4450". The frame requesting access set "document.domain" to "nss.xxx.edu", but the frame being accessed did not. Both must set "document.domain" to the same value to allow access.
The main page's document.domain was set to dev.nss.xxx.edu and the iframe page's document.domain was set to nss.xxx.edu
I added the following JavaScript code to the main page to force the domain to be "nss.xxx.edu" and that fixed the error.
document.domain = "nss.xxx.edu";
Upvotes: 3