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?