kjo
kjo

Reputation: 35321

window.PARAM vs window.parent.PARAM vs window.top.PARAM?

I need to access from several js files a global constant SETTINGS that is defined in a different js file. Researching the matter, I've come across all of the following alternatives:

What's the difference, if any, between these alternatives? Is any one of them considered "best practice"?

Upvotes: 0

Views: 71

Answers (1)

Rob W
Rob W

Reputation: 349042

When the current context is the top frame, then window, top and parent are identical.

Otherwise, window refers to the current context, parent to the parent and top to the top frame.

External scripts run in the same context as the document where they're embedded. So, use window.SETTINGS.

Upvotes: 1

Related Questions