0

I need to find the url of an iframe that will update if a user clicks on a link in the iframe.

i tried using answers from this question ([1] [2]) but it errored

VM98:7 Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame. at iframe.onload (:7:46)

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
WlodekM
  • 1
  • 2
  • Could it be that the link leaves your domain? https://stackoverflow.com/questions/938180/get-current-url-from-iframe/938195#938195 – Gandora Jun 08 '23 at 10:38
  • As the answer you linked to states: `For security reasons, you can only get the url for as long as the contents of the iframe, and the referencing javascript, are served from the same domain`. As this is not the case for you - as demonstrated by the error you're getting - then what you're attempting to do is not possible from client-side JS. – Rory McCrossan Jun 08 '23 at 10:47

1 Answers1

-1

You can try this

var iframe = document.getElementById('your-iframe-id'); // Replace 'your-iframe id' with the actual ID of your iframe 
var currentURL = iframe.src;

console.log(currentURL); // Print the current URL of the iframe