[SalesForce] Reload parent window using top.location.reload

I have a inline VF page and trying to reload the parent window.

I am getting

Uncaught SecurityError: Blocked a frame with origin
"https://ratan.ap1.visual.force.com" from accessing a frame with
origin "https://ap1.salesforce.com". Protocols, domains, and ports
must match.

Error.

Yaah i can understand this is not accessible because of inline VF page and the parent window domain is not same so it behave like this.

It is not make sense to me since the my inline VF page and standard page both are in same org and I am able to access the both page then I should able to access the parent window.

For reloading the page I found the workaround. I can use window.top.location = /object.Id;.

But wanted to know why this is necessary to have. If i am able to view the parent window then this should be accessible in my javascript.

Best Answer

This is happening because of same origin policy.

Why is the same origin policy so important?

Assume you are login to Salesforce org and visit a malicious website in another browser tab. Without same orgin policy the javascript of other tab could do anything with your Salesforce org. For example it can read your data inside the org.

As Salesforce wants to use javascript to enhance the user experience. So it is important that the browser can detect that this JavaScript is trusted to access Salesforce resources. That's where the same origin policy comes into play.