0

I trid to read out the actual path of an iframe, if the user click some button inside of this iframe.

If the user click on the button "weiter" the iframe goes to this link: https://koop.energie.check24.de/.../onlineoffline/. (If you open the link from my iframe in a new broswer tab and klick to "weiter", then you can see the new URL).

The iframe looks like this:

<div id="load-iframe"><p>Loading iframe ...</p></div>
<iframe id="iframe_id" src="https://koop.energie.check24.de/184979/stromsuchen/strom/el/?zipcode=10115&totalconsumption=2000" width="100%" height="400" onload="document.getElementById('load-iframe').style.display='none';"></iframe>

JavaScript option1:

var iframeReference = document.getElementById("iframe_id");
var url = iframeReference ? new URL(iframeReference.src) : undefined;

JavaScript option2:

var url = document.getElementById("iframe_id").contentWindow.location.href;

My idear is to read out the last path of the link for checking the postion of the iframe page. In this case if the user click the button "weiter" the new url is: https://koop.energie.check24.de/.../onlineoffline/ (with the last path of the link /onlineoffline/ I can track the location).

I have tried this, but I get only the original url of the html iframe code or about:blank:

Option1: https://jsfiddle.net/gvyo01u4/23/

Option2: https://jsfiddle.net/d5tr072e/1/

Can someone pleace help me to read out the actuall/updated url of the iframe?

Sinalco
  • 39
  • 5
  • Does this answer your question? [Detect when an iframe starts to load new URL](https://stackoverflow.com/questions/17315013/detect-when-an-iframe-starts-to-load-new-url) – kol Aug 26 '21 at 10:38
  • How can I get the url if the iframe starts to load a new URL? Or can you give me an example? – Sinalco Aug 26 '21 at 11:27
  • I found out something: https://jsfiddle.net/uLyra7fs/9/ Now the JavaScript read out the forwarded URL, if the iframe was reloaded, what is nice. But it takes every time from the starting iframe URL. I need the actual URL. Someone an idea how I can take after every reload on the iframe the last URL? – Sinalco Aug 28 '21 at 12:22

0 Answers0