Access javascript variable from subdomain

585 views Asked by At

I have multiple subdomains and sometimes i have situation to open main domain from sub-domain using window.open and close after doing certain operation.

While doing this activity I need to access javascript variable set on subdomain during page load from opened popup using window.opener.xxx but it says "security issue frame can not be accessed due to cross origin policy".

I tried document.domin = "maindomain.com"; on subdomain but it failed.

How to do it pls help me.

Thanks

2

There are 2 answers

1
IT goldman On

You can pass this variable using querystring like, domain.com/page.html?variable=value and then you can parse that variable using javascript, like this: How can I get query string values in JavaScript?

0
Lance On

Since it's your domain and you have access to the server, you can enable Cross-Origin Resource Sharing.

How To: http://enable-cors.org/