2

I have 2 sub domains

passwordservices.example.com
computers.example.com

All computers are attached to the computers.example.com

A workstation called PC123456 on the domain has a fully qualified name is

PC123456.computers.example.com

The web pages are hosted on passwordservices.

How can I write a javascript that's hosted on PC123456 And access DOM elements on password services.

1
  • That's not exactly cross-domain if it's on the same domain. Commented Aug 18, 2012 at 2:16

1 Answer 1

3

Basically, JS believes that even a subdomain such as img.yourdomain.com is a different domain from www.yourdomain.com. Because of that, AJAX across pages from those two subdomains will not work. Also if you have an iframe from one to another, you will not be able to refence JS vars or functions back and forth.

A way around this involves setting up an iframe html on one domain and then calling that iframe from the page on the other subdomain. You have to set the document.domain to the same thing on both the parent page and its iframe, in order for them to talk to each other.

document.domain = "yourdomain.com"

Source: tomhoppe.com

You might also want to look into Cross-Origin Resource Sharing

Good Luck!!

Sign up to request clarification or add additional context in comments.

2 Comments

A couple additional points of note: 1) you may only set document.domain once (per page). Some browsers will throw if you try to set it back or to something else. 2) Using document.domain is essentially painting yourself into a corner; you will likely be fine, but you must align it on all pages that need to communicate (even two on the same subdomain). All of that being said, it is the easiest solve here.
The domain with passwordservices dynamically generates html. The site is passwordservices.example.com/password.exe?… the parameters will determine the page output. I want to create an iframe to on the computer domain to perform data entry and assist my users to.change their password

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.