0

I am using below code to load some content in iFrame.

<html>
<head></head>
<body>
    <div style="position: absolute; overflow: hidden; left: 0px; top: 0px;  width:550px; height:280px;" onClick=onStopRecording();>
        <div style="overflow: hidden; margin-top: -100px; margin-left: -25px;"></div>
        <iframe id="exIframe" src="http://example.com" scrolling="no" frameborder="0"  style="height: 280px; border: 0px none; width: 550px; margin-top: -60px; margin-left: -24px;"></iframe>
    </div>
    </div>
</body>
</html>

Now when I click the URL inside the iFrame, it needs to redirect to that URL and get loaded in main window itself.

But it is loading inside the iFrame.

Please note that I am using third party site inside the iFrame where I can't change its code

Muhammad Usman
  • 1,366
  • 5
  • 18
  • 33
Sophia Sutter
  • 43
  • 1
  • 6
  • 2
    Please be aware of the [Same-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy) that means that you do not have any control over a page within an iFrame that is NOT in the same domain as the parent page. (Unless you have [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) implemented) – freefaller Oct 01 '15 at 09:22
  • As long as your iFrame is src is not on the same domain of your page, you cannot check what happens inside the iFrame for security reasons (unless CORS is implemented as freefaller pointed out). You can override these security measures in your browser but that's not an acceptable solution for end users. Though, if you override it (or CORS), you could go inside the iFrame with script. Here's an [example](http://stackoverflow.com/questions/2429045/iframe-src-change-event-detection). – Swimburger Oct 01 '15 at 09:52
  • @sniels is there anyway that I can call mutation observer everytime when page loads in iframe? – Sophia Sutter Oct 01 '15 at 11:02
  • @SophiaSutter, to my knowledge, the 'src' attribute doesn't change when you navigate within an iFrame. So you can't read the url via the src attribute. I was referring to [this answer](http://stackoverflow.com/a/2429058/2919731) in my previous comment. But to access aniFrame.contentWindow.location you need to be on the same domain, or have CORS, or override the browser. Short answer, I'm afraid it's not possible to achieve your behaviour without having users override this security functionality in browsers. (I stumbled upon this myself recently) – Swimburger Oct 01 '15 at 11:19
  • ok :( anyway thanks a lot for your suggestions – Sophia Sutter Oct 01 '15 at 11:32
  • @sniels may be I can read the URL from iFrame if CORS is enabled in the server which I use inside the iFrame? – Sophia Sutter Oct 12 '15 at 13:42
  • Yes, in that case you can access everything inside the iFrame through script. – Swimburger Oct 12 '15 at 13:47

0 Answers0