1

Getting directly the current iframe's URL, in javascript, is not possible due to security restriction. Is there a way to override this restriction?

  1. Using ActiveX control?

  2. Changing the browser's security options?

  3. Using HTML5?

  4. Using flash?

  5. Using server side scripting?

3
  • If you find a way to do this other than through method 2 you'll just be relying on a security vulnerability that will probably be fixed in a short amount of time. Commented Nov 2, 2010 at 18:47
  • Can iframe call the parent? Or do you have no control of the iframe? Commented Nov 2, 2010 at 18:50
  • I have no control of the iframe. Commented Nov 2, 2010 at 18:59

2 Answers 2

2

Getting directly the current iframe's URL, in javascript, is not possible due to security restriction

If you mean cross-domain IFrames, and you have no way of controlling the inlying page, then this is correct.

As far as I know, no, there is no way to get around this.

The only way I can think of - and you don't want to go down that road - is proxying every page inside the iframe through a local server script, rewriting every link and action within each page to go through the proxy, too. But that is hugely difficult, comes with a shitload of things to be aware of, and is not a real option - many modern sites will simply break if proxied that way.

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

Comments

0

As I understand it if you have no control of the frame you are not supposed to know what is going on in this frame. So, knowing it would be a security bug and should be fixed. Browsers are designed to not allow the page spy on what you are doing in another page.

If you have control over iFrame there are some options for you

There is a discussion here: How do I get the current location of an iframe?

basically var iframe = document.getElementById('loader').src

You can actually get the location if iframe is located at the same server. If it is located at a different server the only way to go is to rewrite URLs like some sites do. It is not easy to do though

You can also do HTML5 cross-window communication: http://ajaxian.com/archives/cross-window-messaging-with-html-5-postmessage

1 Comment

src will give the initial URL of the iframe, but will fail if the URL has changed in the meantime

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.