简体   繁体   中英

How to get iframe's URL in javascript?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM