0

I am Iframing auto generated data from a platform I am using so I do not have direct access to the Iframes links. So what I was trying to do is write a script that gets the link or a value in the Iframe then redirects the parent page with that link.

Everything is on the same domain, I just cannot edit the page that is auto generating the data so I am using the iframe.

Here is the script I am using / trying to implement and I cannot see what I am doing wrong:

<script>
    function replaceLoad(oIframe) {
        oIframe.onload = function () {
            document.getElementById("replaceLoad").contentWindow.location = "javascript:moveMe()"
        }
    }
</script>

This is the the iframe html:

<iframe scrolling="no" src="http://www.discoverhomefinder.com/dljones/homes-for-sale/AZ/Anthem?wmode=opaque" frameborder="0" style="border: 0px none; margin-left: 0px; height: 3900px; margin-top: -12%; width: 100%;" onload="replaceLoad(this)">
</iframe>
algib
  • 70
  • 1
  • 9
  • My answer on the following post may be what you're looking for: http://stackoverflow.com/questions/23858219/lengthening-an-iframe-from-another-page-within-the-iframe-itself Also, you should not use javascript in hrefs, it's bad practice. :) – JakeSidSmith May 26 '14 at 16:45
  • You can update the iframe's location by changing it's src. – JakeSidSmith May 26 '14 at 16:45
  • The question is about _parent page_, also, the iframe doesn't have an id with `replaceLoad` so it'll never find it. Thirdly, redirecting the parent page could be done with `window.top.location.href = "url.com"`. – Henrik Andersson May 26 '14 at 16:47
  • Would that work if I have no control over the code of the links in the iframe. They are auto generated on the system. – algib May 26 '14 at 16:48
  • and im not trying to redirect to a certain link i have a page with multiple listings on it and any link clicked i need redirect to the parent link to the `src` of the link – algib May 26 '14 at 16:48
  • Apart from that this isn't working (obviously) this is roughly what you want: http://jsbin.com/zexalogi/2/ – Henrik Andersson May 26 '14 at 16:54
  • no, you can see what im doing here....http://www.rrtest13.com i am trying to click to the actual link inside the iframe. I am aware of redirecting to a certain url but that is not my goal – algib May 26 '14 at 16:55
  • What you could do is listen for a change of the src attribute on the iframe. Upon change, you could use that src and redirect your actual page to that same url. This may be a good starting point: http://stackoverflow.com/questions/2429045/iframe-src-change-event-detection – Pevara May 26 '14 at 17:18

1 Answers1

0

As I understand, you just wanna redirect the parent page to the url of the iframe, you can just do this in your function :

function replaceLoad(oIframe) {
    window.location.href = oIframe.src;
}
Dragonize
  • 1
  • 1