0

I need to get the page url of what the iframe on my pages are on, as we use the iframe to deal with ordering products. However, for the life of me I can't seem to get it to display the iframe's URL (display is a test, as it will auto-email when I see it works)

The code:

<button onClick="myFunction()">Test</button>
<script>
function myFunction() {
alert(document.getElementById("iFrame").documentWindow.location.href);
}
</script> 
<iframe src="https://iframe.mydomain.co.uk" id="iFrame" width="98%" height="100%"></iframe>

This code is being used on https://products.mydomain.co.uk. The alert, as I said, is only there so I can just press the button to see it showing the new domain, so that I can do what is needed for the rest of it.

Any ideas?

jordsta95
  • 119
  • 1
  • 9

1 Answers1

0

add document.domain = 'your.domain' in both the pages.

like this. don't forget both parent.top

document.domain = 'corp.local';

only parent like

document.domain = 'corp';

won't work.

Mashhoor Gulati
  • 127
  • 3
  • 13