Search code examples
javascriptjqueryiframecross-domainsame-origin-policy

getting src i.e. url of iframe so that parent page can use it?


Probably, I know the answer already that there is no way by which I can read the DOM Values of Iframe so that Parent can use it.

I spent lot of time researching about it but can not find any way, hence posting it here.

CONSTRAINTS :

Different Domains, No Control over the iframe url. It can be any URL provided by the user.

WHAT I TRIED SO FAR :

I need the value of the url i.e. window.frames['iframename'].location.href but I am getting permission denied as it violates same origin policy.

HTML5 Post message api wont work as it assumes even if they are cross - domain we have control over the iframe page.

easyXSD also assumes the same I suppose.

Is it possible at all?

NOTE : USER Will Change the SRC from Iframe itself. so I use onload method to do something but not able to access location.href


Solution

  • If you have no control over the iframe, then it is not possible since it is a security risk. Notice that you may set the location/url of an iframe/window, but you can not read it (if it is cross domain).

    If you had control over the iframe, then workarounds would be possible (using postMessage, workers or whatever).