cmplieger
cmplieger

Reputation: 7371

Update URL from inside an iFrame

is it possible for javascript inside an iFrame to update the URL (hash) of the parent page (and retrieve it) Does it have any permissions?

To further explain, I have no hosting for this domain, I can only set up an Iframe. I also cannot use a DNS config to get that page to display because of limitations of my hoster. I also cannot transfer the domain to them to make that work because my clients wants to keep control of the domain.

Thank you for your help!

Upvotes: 3

Views: 733

Answers (3)

arpad
arpad

Reputation: 539

To be short, the answer is NO.

Your script works only inside the context of that iframe. If you try for example,

var loc = document.location;

you will see what I mean.

One solution is that when you give the other side your iframe, you should add a script in witch you can do whatever you want, because it runs on their domain. Maybe dynamically create the source of your iframe and stuff.

Upvotes: 1

richardtz
richardtz

Reputation: 4993

due to security constraints you will not be able to access properties of the parent window IF the domain,port or protocol is different than the one in the iframe.

Upvotes: 2

Ja͢ck
Ja͢ck

Reputation: 173662

If the <iframe> page is within the same domain, probably yes. Otherwise you don't get access to the parent page due to cross-domain restrictions.

You can change the URL of the parent page though:

top.location.href = 'http://www.example.com';

Upvotes: 2

Related Questions