Darren Young
Darren Young

Reputation: 11090

Javascript document.domain

I'm trying to access a work server for use with an application called Spotfire. My colleague who passed me this is now off for a couple of weeks, and I have an issue with what he advised me.

Effectively when I run my web app via localhost, I get an error saying that I cannot access my work server. My colleague had said that I need to set document.domain to our work domain, but when I do this as such:

document.domain = "workdomain.net";

I get an error saying that it is an invalid argument. Any idea how to get around this?

Thanks,

Darren.

Upvotes: 5

Views: 12116

Answers (1)

Ash Eldritch
Ash Eldritch

Reputation: 1514

From https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript

"A script can set the value of document.domain to a subset of the current domain. If it does so, the shorter domain is used for subsequent origin checks."

The reason you're getting the javascript error is because you're trying to set the document.domain to a completely different domain than your current one ("localhost").

Rather than this, I suggest you add an entry to your host file...

127.0.0.1 local.workdomain.net

...and then navigate to local.workdomain.net

Upvotes: 9

Related Questions